#include <bits/stdc++.h> using namespace std; #ifndef _WIN32 #define getchar getchar_unlocked #endif #define MP make_pair #define PB push_back #define ST first #define ND second #define ALL(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) //#define int LLI #define FOR(i,a,b) for(int i = (a); i <= (b); ++i) #define REP(i,n) FOR(i,0,(int)(n)-1) #define F1(i,n) FOR(i,1,n) typedef long long LLI; typedef unsigned long long LLU; typedef long double LD; typedef pair<int, int> pii; typedef pair<LLI, LLI> pll; typedef vector<int> vi; #ifdef ONLINE_JUDGE ostream cnull(NULL); #define cerr cnull #endif template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";} template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',') cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define dbgV(R) {cerr << #R << "=["; for(int e : R) cerr << e << ", "; cerr << "E]\n";} #define dbgA(R, n) {cerr << #R << "=["; for(int i = 0; i <= n; ++i) cerr << R[i] << ", "; cerr << "E]\n";} #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) const int BLEP = 17; LLI pot10[BLEP + 1]; template <typename T> int _log(T x){ int wyn = 0; while(x) ++wyn, x /= 10; return wyn; } int lex(string &A, string &b){ for(int i = 0; i < SZ(b); ++i){ if(A[i] < b[i]) return -1; if(A[i] > b[i]) return 1; } return 0; } const string atrapa = "000000000000000000"; int32_t main() { boost; pot10[0] = 1; F1(i, BLEP) pot10[i] = pot10[i - 1] * 10ll; int n; cin >> n; LLI wyn = 0; LLI A; cin >> A; string s = " "; int dl = _log<LLI>(A); bool dlugi = 0; REP(i, n - 1){ if(!dlugi){ //dbg(A, dl); int b; cin >> b; int dlB = _log<int>(b); if(dlB > dl) A = b, dl = dlB; else{ LLI truncA = A / pot10[dl - dlB]; //dbg(truncA); dbg(dl); if(b > truncA) A = b * pot10[dl - dlB]; else if(b < truncA) A = b * pot10[dl - dlB + 1], ++dl; else{ ++A; LLI dlA = _log<LLI>(A); LLI trunc2A = A / pot10[dlA - dlB]; if(b == trunc2A) dl = dlA; else A = b * pot10[dl - dlB + 1], ++dl; } } wyn += dl - dlB; if(dl > BLEP){ dlugi = 1; s = to_string(A); } //dbg(A); } else{ string b; cin >> b; int cmp = lex(s, b); //dbg(s, b, dl); if(cmp != 0){ s = b + atrapa; dl += max(0, cmp); } wyn += dl - SZ(b); } } cout << wyn; } /* 2 5 5 */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #include <bits/stdc++.h> using namespace std; #ifndef _WIN32 #define getchar getchar_unlocked #endif #define MP make_pair #define PB push_back #define ST first #define ND second #define ALL(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) //#define int LLI #define FOR(i,a,b) for(int i = (a); i <= (b); ++i) #define REP(i,n) FOR(i,0,(int)(n)-1) #define F1(i,n) FOR(i,1,n) typedef long long LLI; typedef unsigned long long LLU; typedef long double LD; typedef pair<int, int> pii; typedef pair<LLI, LLI> pll; typedef vector<int> vi; #ifdef ONLINE_JUDGE ostream cnull(NULL); #define cerr cnull #endif template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";} template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',') cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define dbgV(R) {cerr << #R << "=["; for(int e : R) cerr << e << ", "; cerr << "E]\n";} #define dbgA(R, n) {cerr << #R << "=["; for(int i = 0; i <= n; ++i) cerr << R[i] << ", "; cerr << "E]\n";} #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) const int BLEP = 17; LLI pot10[BLEP + 1]; template <typename T> int _log(T x){ int wyn = 0; while(x) ++wyn, x /= 10; return wyn; } int lex(string &A, string &b){ for(int i = 0; i < SZ(b); ++i){ if(A[i] < b[i]) return -1; if(A[i] > b[i]) return 1; } return 0; } const string atrapa = "000000000000000000"; int32_t main() { boost; pot10[0] = 1; F1(i, BLEP) pot10[i] = pot10[i - 1] * 10ll; int n; cin >> n; LLI wyn = 0; LLI A; cin >> A; string s = " "; int dl = _log<LLI>(A); bool dlugi = 0; REP(i, n - 1){ if(!dlugi){ //dbg(A, dl); int b; cin >> b; int dlB = _log<int>(b); if(dlB > dl) A = b, dl = dlB; else{ LLI truncA = A / pot10[dl - dlB]; //dbg(truncA); dbg(dl); if(b > truncA) A = b * pot10[dl - dlB]; else if(b < truncA) A = b * pot10[dl - dlB + 1], ++dl; else{ ++A; LLI dlA = _log<LLI>(A); LLI trunc2A = A / pot10[dlA - dlB]; if(b == trunc2A) dl = dlA; else A = b * pot10[dl - dlB + 1], ++dl; } } wyn += dl - dlB; if(dl > BLEP){ dlugi = 1; s = to_string(A); } //dbg(A); } else{ string b; cin >> b; int cmp = lex(s, b); //dbg(s, b, dl); if(cmp != 0){ s = b + atrapa; dl += max(0, cmp); } wyn += dl - SZ(b); } } cout << wyn; } /* 2 5 5 */ |