#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int hop[1200][3];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> v(N);
vector<vector<int> > ans(N);
for (int &i : v) cin >> i;
for (int i = N - 1; i >= 0; i--) {
int k = 0;
for (int j = i + 1; j < N; j++) {
for (; k < 3; k++) {
if (v[j] % v[i]) {
ans[j].pb(k);
break;
}
if (hop[j][k] < 3) {
ans[j].pb(k);
hop[i][k] = max(hop[i][k], hop[j][k] + 1);
break;
}
if (k == 2) {
k = 0;
ans[j].pb(rng() % 3);
break;
}
}
}
}
// for (int j = 0; j < N; j++) {
// for (int k = 0; k < 3; k++) {
// cout << hop[j][k] << " ";
// }
// cout << endl;
// }
for (int i = 0; i < N; i++) {
reverse(ans[i].begin(), ans[i].end());
for (int x : ans[i]) {
cout << x + 1 << " ";
}
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
35 ms |
6728 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
31 ms |
5772 KB |
Output is correct |
12 |
Correct |
34 ms |
6620 KB |
Output is correct |
13 |
Correct |
31 ms |
5872 KB |
Output is correct |
14 |
Correct |
2 ms |
576 KB |
Output is correct |
15 |
Correct |
31 ms |
5996 KB |
Output is correct |
16 |
Correct |
30 ms |
5956 KB |
Output is correct |
17 |
Correct |
31 ms |
6204 KB |
Output is correct |
18 |
Correct |
31 ms |
6012 KB |
Output is correct |
19 |
Correct |
32 ms |
5956 KB |
Output is correct |
20 |
Correct |
31 ms |
5956 KB |
Output is correct |
21 |
Correct |
31 ms |
5952 KB |
Output is correct |
22 |
Correct |
30 ms |
5948 KB |
Output is correct |
23 |
Correct |
34 ms |
6544 KB |
Output is correct |