-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm.cpp
58 lines (55 loc) · 1.02 KB
/
m.cpp
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
#include <bits/stdc++.h>
using namespace std;
bool upd(string &a, string &b) {
long long x = stoll(a), y = stoll(b);
for (int i = 0; i < (int)a.size(); i++) {
string cur = a;
cur[i] = '9';
if (stoll(cur) > y) {
a = cur;
return true;
}
}
if ((int)b.size() == 1 && x > 0) {
b = "0";
return true;
}
for (int i = 0; i < (int)b.size(); i++) {
string cur = b;
if (i == 0) {
cur[i] = '1';
if (stoll(cur) < x) {
b = cur;
return true;
}
} else {
cur[i] = '0';
if (stoll(cur) < x) {
b = cur;
return true;
}
}
}
return false;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> a(n);
for (string &s : a)
cin >> s;
for (int i = 0; i < n - 1; i++) {
if (upd(a[i], a[i + 1])) {
for (int j = 0; j < n; j++) {
if (j > 0) cout << ' ';
cout << a[j];
}
cout << '\n';
return 0;
}
}
cout << "impossible\n";
return 0;
}