#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
using num = vector<int>;
num sub(num a, num b) {
// for (int e : a) {
// cout << e;
// }
// cout << endl;
// for (int e : b) {
// cout << e;
// }
// cout << endl;
assert(a.size() >= b.size());
int carry = 0;
for (int i = 0; i < (int)a.size(); ++i) {
carry += a[i];
if (i < (int)b.size()) {
carry -= b[i];
}
while (carry < 0) {
assert(i + 1 < (int)a.size());
carry += 10;
a[i + 1] -= 1;
}
assert(carry < 10);
a[i] = carry;
carry = 0;
}
while (a.size() >= 2 && !a.back()) {
a.pop_back();
}
return a;
}
const int N = 1e5;
int n;
num dp[N];
int a[N];
vector<int> pos;
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
dp[i].clear();
reverse(all(s));
for (char c : s) {
dp[i].push_back(c - '0');
}
}
for (int i = n - 1; i >= 1; --i) {
dp[i] = sub(dp[i], dp[i - 1]);
}
for (int i = 0; i < n; ++i) {
int ind = 0;
num least = dp[i];
while (ind < (int)pos.size() && (least.size() >= 2 || least.front() != 1)) {
least = sub(least, dp[pos[ind]]);
++ind;
}
pos.insert(pos.begin() + ind, i);
}
for (int i = 0; i < n; ++i) {
a[pos[i]] = i + 1;
}
for (int i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
74 ms |
3052 KB |
Output is correct |
4 |
Correct |
104 ms |
3052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
74 ms |
3052 KB |
Output is correct |
4 |
Correct |
104 ms |
3052 KB |
Output is correct |
5 |
Execution timed out |
4072 ms |
34284 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
74 ms |
3052 KB |
Output is correct |
4 |
Correct |
104 ms |
3052 KB |
Output is correct |
5 |
Execution timed out |
4072 ms |
34284 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
74 ms |
3052 KB |
Output is correct |
4 |
Correct |
104 ms |
3052 KB |
Output is correct |
5 |
Execution timed out |
4072 ms |
34284 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
74 ms |
3052 KB |
Output is correct |
4 |
Correct |
104 ms |
3052 KB |
Output is correct |
5 |
Execution timed out |
4072 ms |
34284 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
74 ms |
3052 KB |
Output is correct |
4 |
Correct |
104 ms |
3052 KB |
Output is correct |
5 |
Execution timed out |
4072 ms |
34284 KB |
Time limit exceeded |