Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <cmath>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <set>
#include <unordered_set>
#define M_PI 3.14159265358979323846
#define ull unsigned long long
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<long long>
#define vull vector<unsigned long long>
#define v vector
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
using namespace std;
map<int, string> mp;
string get(int n) {
if(mp.find(n) == mp.end()) return mp[n] = string(n, '0');
return mp[n];
}
int main()
{
ios_base::sync_with_stdio(0);
int n,a;
cin >> n;
v<pair<ll, string>> t;
for (int i = 0; i < n; ++i) {
cin >> a;
t.push_back({ a, to_string(a) });
}
ll all = 0;
int prevlen, curlen, pref, missing, zeros, it;
for (int i = 1; i < n; ++i) {
if (t[i - 1].first >= t[i].first || t[i - 1].second.length() > 10 ) {
prevlen = t[i - 1].second.length();
curlen = t[i].second.length();
if (prevlen == curlen) {
all += 1;
t[i].second += '0';
if (curlen < 10) {
t[i].first *= 10;
}
}
else {
// poprzednia jest d�u�sza
pref = stoi(t[i - 1].second.substr(0, curlen));
if (pref < t[i].first) { // wystarczy dokleic zera
missing = prevlen - curlen;
all += missing;
t[i].second += get(missing);
if (t[i].second.length() <= 10) {
for (int j = 0; j < missing; ++j) {
t[i].first *= 10;
}
}
}
else if(pref > t[i].first){
// wystarczy dokleic wiecej zer
missing = prevlen - curlen + 1; // !
all += missing;
t[i].second += get(missing);
if (t[i].second.length() <= 10) {
for (int j = 0; j < missing; ++j) {
t[i].first *= 10;
}
}
}
else {
// rowne prefiksy, doklej koniec o 1 wiekszy
it = prevlen - 1;
zeros = 0;
while (it >= curlen && t[i-1].second[it] == '9') {
it--;
zeros++;
}
string app;
if (it < curlen) {// same 9
app = get(zeros + 1);
all += zeros + 1;
}
else {
app = char(t[i-1].second[it] + 1) + get(zeros);
app = t[i - 1].second.substr(curlen,it - curlen) + app;
all += prevlen - curlen;
}
//all += zeros + 1;
t[i].second += app;
if (t[i].second.length() <= 10) {
t[i].first = stoll(t[i].second);
}
}
}
}
}
cout << all << endl;
}
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 | #include <cmath> #include <map> #include <string> #include <vector> #include <algorithm> #include <iostream> #include <cmath> #include <iomanip> #include <set> #include <unordered_set> #define M_PI 3.14159265358979323846 #define ull unsigned long long #define ll long long #define ld long double #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vb vector<bool> #define vll vector<long long> #define vull vector<unsigned long long> #define v vector #define vii vector<pair<int,int>> #define vvi vector<vector<int>> using namespace std; map<int, string> mp; string get(int n) { if(mp.find(n) == mp.end()) return mp[n] = string(n, '0'); return mp[n]; } int main() { ios_base::sync_with_stdio(0); int n,a; cin >> n; v<pair<ll, string>> t; for (int i = 0; i < n; ++i) { cin >> a; t.push_back({ a, to_string(a) }); } ll all = 0; int prevlen, curlen, pref, missing, zeros, it; for (int i = 1; i < n; ++i) { if (t[i - 1].first >= t[i].first || t[i - 1].second.length() > 10 ) { prevlen = t[i - 1].second.length(); curlen = t[i].second.length(); if (prevlen == curlen) { all += 1; t[i].second += '0'; if (curlen < 10) { t[i].first *= 10; } } else { // poprzednia jest d�u�sza pref = stoi(t[i - 1].second.substr(0, curlen)); if (pref < t[i].first) { // wystarczy dokleic zera missing = prevlen - curlen; all += missing; t[i].second += get(missing); if (t[i].second.length() <= 10) { for (int j = 0; j < missing; ++j) { t[i].first *= 10; } } } else if(pref > t[i].first){ // wystarczy dokleic wiecej zer missing = prevlen - curlen + 1; // ! all += missing; t[i].second += get(missing); if (t[i].second.length() <= 10) { for (int j = 0; j < missing; ++j) { t[i].first *= 10; } } } else { // rowne prefiksy, doklej koniec o 1 wiekszy it = prevlen - 1; zeros = 0; while (it >= curlen && t[i-1].second[it] == '9') { it--; zeros++; } string app; if (it < curlen) {// same 9 app = get(zeros + 1); all += zeros + 1; } else { app = char(t[i-1].second[it] + 1) + get(zeros); app = t[i - 1].second.substr(curlen,it - curlen) + app; all += prevlen - curlen; } //all += zeros + 1; t[i].second += app; if (t[i].second.length() <= 10) { t[i].first = stoll(t[i].second); } } } } } cout << all << endl; } |
English