# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173971 | 2020-01-05T22:03:08 Z | mcdx9524 | Nice sequence (IZhO18_sequence) | C++14 | 2000 ms | 74912 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r) { return uniform_int_distribution<int> (l, r) (rnd); } const int N = 5e5 + 7; int n, m; vector <int> p; vector <int> ord; vector <int> g[N]; bool used[N]; int col[N]; bool cycle(int v) { col[v] = 1; for (int u : g[v]) { if (col[u] == 0) { if (cycle(u)) { return true; } } else if (col[u] == 1) { return true; } } col[v] = 2; return false; } void dfs(int v) { if (used[v] == true) { return; } used[v] = true; for (int u : g[v]) { dfs(u); } ord.push_back(v); } bool build(int sz, bool kek) { ord.clear(); for (int i = 0; i < N; i++) { g[i].clear(); used[i] = false; col[i] = 0; } for (int i = 1; i <= sz; i++) { // p[i] - p[i - n] < 0 // p[i] < p[i - n] if (i - n >= 0) { g[i - n].push_back(i); } // p[i] > p[i - m] if (i - m >= 0) { g[i].push_back(i - m); } } for (int i = 0; i <= sz; i++) { if (cycle(i)) { return false; } } if (!kek) return true; for (int i = 0; i <= sz; i++) { dfs(i); } p.resize(sz + 1, 0); int cur = sz; reverse(ord.begin(), ord.end()); for (int x : ord) { p[x] = cur--; } for (int i = 0; i <= sz; i++) { if (!p[i]) { p[i] = cur--; } } return true; } void solve() { cin >> n >> m; int l = max(n, m) - 1, r = n + m + 7; int ans = n + m - 1 - __gcd(n, m); /* while (l <= r) { int md = rand(l, r); if (build(md, 0)) { l = md + 1; ans = md; } else { r = md - 1; } } */ build(ans, 1); cout << ans << '\n'; for (int i = 1; i <= ans; i++) { cout << p[i] - p[i - 1] << ' '; } cout << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 14456 KB | Ok |
2 | Correct | 26 ms | 14584 KB | Ok |
3 | Correct | 26 ms | 14456 KB | Ok |
4 | Correct | 26 ms | 14536 KB | Ok |
5 | Correct | 26 ms | 14456 KB | Ok |
6 | Correct | 26 ms | 14456 KB | Ok |
7 | Correct | 26 ms | 14456 KB | Ok |
8 | Correct | 26 ms | 14456 KB | Ok |
9 | Correct | 26 ms | 14584 KB | Ok |
10 | Correct | 26 ms | 14584 KB | Ok |
11 | Correct | 26 ms | 14584 KB | Ok |
12 | Correct | 26 ms | 14456 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 14456 KB | Ok |
2 | Correct | 26 ms | 14456 KB | Ok |
3 | Correct | 31 ms | 14584 KB | Ok |
4 | Correct | 26 ms | 14516 KB | Ok |
5 | Correct | 26 ms | 14572 KB | Ok |
6 | Correct | 28 ms | 14712 KB | Ok |
7 | Correct | 37 ms | 15592 KB | Ok |
8 | Correct | 31 ms | 14968 KB | Ok |
9 | Correct | 38 ms | 15736 KB | Ok |
10 | Correct | 34 ms | 15224 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 14584 KB | Ok |
2 | Correct | 26 ms | 14456 KB | Ok |
3 | Correct | 26 ms | 14584 KB | Ok |
4 | Correct | 27 ms | 14584 KB | Ok |
5 | Correct | 30 ms | 14584 KB | Ok |
6 | Correct | 27 ms | 14584 KB | Ok |
7 | Correct | 26 ms | 14456 KB | Ok |
8 | Correct | 26 ms | 14588 KB | Ok |
9 | Correct | 31 ms | 14456 KB | Ok |
10 | Correct | 32 ms | 14584 KB | Ok |
11 | Correct | 27 ms | 14596 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 14456 KB | Ok |
2 | Correct | 33 ms | 14604 KB | Ok |
3 | Correct | 26 ms | 14584 KB | Ok |
4 | Correct | 27 ms | 14584 KB | Ok |
5 | Correct | 28 ms | 14456 KB | Ok |
6 | Correct | 148 ms | 27496 KB | Ok |
7 | Correct | 137 ms | 33736 KB | Ok |
8 | Correct | 219 ms | 36348 KB | Ok |
9 | Correct | 170 ms | 33704 KB | Ok |
10 | Correct | 109 ms | 24452 KB | Ok |
11 | Correct | 163 ms | 30356 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 14456 KB | Ok |
2 | Correct | 26 ms | 14584 KB | Ok |
3 | Correct | 26 ms | 14456 KB | Ok |
4 | Correct | 26 ms | 14536 KB | Ok |
5 | Correct | 26 ms | 14456 KB | Ok |
6 | Correct | 26 ms | 14456 KB | Ok |
7 | Correct | 26 ms | 14456 KB | Ok |
8 | Correct | 26 ms | 14456 KB | Ok |
9 | Correct | 26 ms | 14584 KB | Ok |
10 | Correct | 26 ms | 14584 KB | Ok |
11 | Correct | 26 ms | 14584 KB | Ok |
12 | Correct | 26 ms | 14456 KB | Ok |
13 | Correct | 20 ms | 14584 KB | Ok |
14 | Correct | 26 ms | 14456 KB | Ok |
15 | Correct | 26 ms | 14584 KB | Ok |
16 | Correct | 27 ms | 14584 KB | Ok |
17 | Correct | 30 ms | 14584 KB | Ok |
18 | Correct | 27 ms | 14584 KB | Ok |
19 | Correct | 26 ms | 14456 KB | Ok |
20 | Correct | 26 ms | 14588 KB | Ok |
21 | Correct | 31 ms | 14456 KB | Ok |
22 | Correct | 32 ms | 14584 KB | Ok |
23 | Correct | 27 ms | 14596 KB | Ok |
24 | Correct | 29 ms | 14840 KB | Ok |
25 | Correct | 28 ms | 14772 KB | Ok |
26 | Correct | 28 ms | 14712 KB | Ok |
27 | Correct | 28 ms | 14712 KB | Ok |
28 | Correct | 28 ms | 14712 KB | Ok |
29 | Correct | 28 ms | 14640 KB | Ok |
30 | Correct | 27 ms | 14712 KB | Ok |
31 | Correct | 28 ms | 14712 KB | Ok |
32 | Correct | 28 ms | 14712 KB | Ok |
33 | Correct | 28 ms | 14716 KB | Ok |
34 | Correct | 30 ms | 14968 KB | Ok |
35 | Correct | 31 ms | 14956 KB | Ok |
36 | Correct | 31 ms | 14968 KB | Ok |
37 | Correct | 31 ms | 14968 KB | Ok |
38 | Correct | 31 ms | 14968 KB | Ok |
39 | Correct | 32 ms | 14968 KB | Ok |
40 | Correct | 33 ms | 14968 KB | Ok |
41 | Correct | 32 ms | 14888 KB | Ok |
42 | Correct | 31 ms | 14840 KB | Ok |
43 | Correct | 33 ms | 15044 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 14456 KB | Ok |
2 | Correct | 26 ms | 14584 KB | Ok |
3 | Correct | 26 ms | 14456 KB | Ok |
4 | Correct | 26 ms | 14536 KB | Ok |
5 | Correct | 26 ms | 14456 KB | Ok |
6 | Correct | 26 ms | 14456 KB | Ok |
7 | Correct | 26 ms | 14456 KB | Ok |
8 | Correct | 26 ms | 14456 KB | Ok |
9 | Correct | 26 ms | 14584 KB | Ok |
10 | Correct | 26 ms | 14584 KB | Ok |
11 | Correct | 26 ms | 14584 KB | Ok |
12 | Correct | 26 ms | 14456 KB | Ok |
13 | Correct | 32 ms | 14456 KB | Ok |
14 | Correct | 26 ms | 14456 KB | Ok |
15 | Correct | 31 ms | 14584 KB | Ok |
16 | Correct | 26 ms | 14516 KB | Ok |
17 | Correct | 26 ms | 14572 KB | Ok |
18 | Correct | 28 ms | 14712 KB | Ok |
19 | Correct | 37 ms | 15592 KB | Ok |
20 | Correct | 31 ms | 14968 KB | Ok |
21 | Correct | 38 ms | 15736 KB | Ok |
22 | Correct | 34 ms | 15224 KB | Ok |
23 | Correct | 20 ms | 14584 KB | Ok |
24 | Correct | 26 ms | 14456 KB | Ok |
25 | Correct | 26 ms | 14584 KB | Ok |
26 | Correct | 27 ms | 14584 KB | Ok |
27 | Correct | 30 ms | 14584 KB | Ok |
28 | Correct | 27 ms | 14584 KB | Ok |
29 | Correct | 26 ms | 14456 KB | Ok |
30 | Correct | 26 ms | 14588 KB | Ok |
31 | Correct | 31 ms | 14456 KB | Ok |
32 | Correct | 32 ms | 14584 KB | Ok |
33 | Correct | 27 ms | 14596 KB | Ok |
34 | Correct | 29 ms | 14840 KB | Ok |
35 | Correct | 28 ms | 14772 KB | Ok |
36 | Correct | 28 ms | 14712 KB | Ok |
37 | Correct | 28 ms | 14712 KB | Ok |
38 | Correct | 28 ms | 14712 KB | Ok |
39 | Correct | 28 ms | 14640 KB | Ok |
40 | Correct | 27 ms | 14712 KB | Ok |
41 | Correct | 28 ms | 14712 KB | Ok |
42 | Correct | 28 ms | 14712 KB | Ok |
43 | Correct | 28 ms | 14716 KB | Ok |
44 | Correct | 30 ms | 14968 KB | Ok |
45 | Correct | 31 ms | 14956 KB | Ok |
46 | Correct | 31 ms | 14968 KB | Ok |
47 | Correct | 31 ms | 14968 KB | Ok |
48 | Correct | 31 ms | 14968 KB | Ok |
49 | Correct | 32 ms | 14968 KB | Ok |
50 | Correct | 33 ms | 14968 KB | Ok |
51 | Correct | 32 ms | 14888 KB | Ok |
52 | Correct | 31 ms | 14840 KB | Ok |
53 | Correct | 33 ms | 15044 KB | Ok |
54 | Correct | 126 ms | 19756 KB | Ok |
55 | Correct | 142 ms | 20176 KB | Ok |
56 | Correct | 152 ms | 20148 KB | Ok |
57 | Correct | 99 ms | 19116 KB | Ok |
58 | Correct | 114 ms | 19580 KB | Ok |
59 | Correct | 106 ms | 19364 KB | Ok |
60 | Correct | 94 ms | 18884 KB | Ok |
61 | Correct | 102 ms | 19476 KB | Ok |
62 | Correct | 129 ms | 20044 KB | Ok |
63 | Correct | 114 ms | 19264 KB | Ok |
64 | Correct | 141 ms | 20056 KB | Ok |
65 | Correct | 122 ms | 19892 KB | Ok |
66 | Correct | 115 ms | 19632 KB | Ok |
67 | Correct | 108 ms | 19336 KB | Ok |
68 | Correct | 115 ms | 19736 KB | Ok |
69 | Correct | 266 ms | 29280 KB | Ok |
70 | Correct | 255 ms | 29752 KB | Ok |
71 | Correct | 261 ms | 29160 KB | Ok |
72 | Correct | 258 ms | 29288 KB | Ok |
73 | Correct | 245 ms | 28520 KB | Ok |
74 | Correct | 262 ms | 28136 KB | Ok |
75 | Correct | 260 ms | 28400 KB | Ok |
76 | Correct | 257 ms | 29388 KB | Ok |
77 | Correct | 268 ms | 27872 KB | Ok |
78 | Correct | 272 ms | 28140 KB | Ok |
79 | Correct | 272 ms | 28904 KB | Ok |
80 | Correct | 264 ms | 29160 KB | Ok |
81 | Correct | 280 ms | 28276 KB | Ok |
82 | Correct | 269 ms | 28776 KB | Ok |
83 | Correct | 260 ms | 28392 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 14456 KB | Ok |
2 | Correct | 26 ms | 14584 KB | Ok |
3 | Correct | 26 ms | 14456 KB | Ok |
4 | Correct | 26 ms | 14536 KB | Ok |
5 | Correct | 26 ms | 14456 KB | Ok |
6 | Correct | 26 ms | 14456 KB | Ok |
7 | Correct | 26 ms | 14456 KB | Ok |
8 | Correct | 26 ms | 14456 KB | Ok |
9 | Correct | 26 ms | 14584 KB | Ok |
10 | Correct | 26 ms | 14584 KB | Ok |
11 | Correct | 26 ms | 14584 KB | Ok |
12 | Correct | 26 ms | 14456 KB | Ok |
13 | Correct | 32 ms | 14456 KB | Ok |
14 | Correct | 26 ms | 14456 KB | Ok |
15 | Correct | 31 ms | 14584 KB | Ok |
16 | Correct | 26 ms | 14516 KB | Ok |
17 | Correct | 26 ms | 14572 KB | Ok |
18 | Correct | 28 ms | 14712 KB | Ok |
19 | Correct | 37 ms | 15592 KB | Ok |
20 | Correct | 31 ms | 14968 KB | Ok |
21 | Correct | 38 ms | 15736 KB | Ok |
22 | Correct | 34 ms | 15224 KB | Ok |
23 | Correct | 20 ms | 14584 KB | Ok |
24 | Correct | 26 ms | 14456 KB | Ok |
25 | Correct | 26 ms | 14584 KB | Ok |
26 | Correct | 27 ms | 14584 KB | Ok |
27 | Correct | 30 ms | 14584 KB | Ok |
28 | Correct | 27 ms | 14584 KB | Ok |
29 | Correct | 26 ms | 14456 KB | Ok |
30 | Correct | 26 ms | 14588 KB | Ok |
31 | Correct | 31 ms | 14456 KB | Ok |
32 | Correct | 32 ms | 14584 KB | Ok |
33 | Correct | 27 ms | 14596 KB | Ok |
34 | Correct | 33 ms | 14456 KB | Ok |
35 | Correct | 33 ms | 14604 KB | Ok |
36 | Correct | 26 ms | 14584 KB | Ok |
37 | Correct | 27 ms | 14584 KB | Ok |
38 | Correct | 28 ms | 14456 KB | Ok |
39 | Correct | 148 ms | 27496 KB | Ok |
40 | Correct | 137 ms | 33736 KB | Ok |
41 | Correct | 219 ms | 36348 KB | Ok |
42 | Correct | 170 ms | 33704 KB | Ok |
43 | Correct | 109 ms | 24452 KB | Ok |
44 | Correct | 163 ms | 30356 KB | Ok |
45 | Correct | 29 ms | 14840 KB | Ok |
46 | Correct | 28 ms | 14772 KB | Ok |
47 | Correct | 28 ms | 14712 KB | Ok |
48 | Correct | 28 ms | 14712 KB | Ok |
49 | Correct | 28 ms | 14712 KB | Ok |
50 | Correct | 28 ms | 14640 KB | Ok |
51 | Correct | 27 ms | 14712 KB | Ok |
52 | Correct | 28 ms | 14712 KB | Ok |
53 | Correct | 28 ms | 14712 KB | Ok |
54 | Correct | 28 ms | 14716 KB | Ok |
55 | Correct | 30 ms | 14968 KB | Ok |
56 | Correct | 31 ms | 14956 KB | Ok |
57 | Correct | 31 ms | 14968 KB | Ok |
58 | Correct | 31 ms | 14968 KB | Ok |
59 | Correct | 31 ms | 14968 KB | Ok |
60 | Correct | 32 ms | 14968 KB | Ok |
61 | Correct | 33 ms | 14968 KB | Ok |
62 | Correct | 32 ms | 14888 KB | Ok |
63 | Correct | 31 ms | 14840 KB | Ok |
64 | Correct | 33 ms | 15044 KB | Ok |
65 | Correct | 126 ms | 19756 KB | Ok |
66 | Correct | 142 ms | 20176 KB | Ok |
67 | Correct | 152 ms | 20148 KB | Ok |
68 | Correct | 99 ms | 19116 KB | Ok |
69 | Correct | 114 ms | 19580 KB | Ok |
70 | Correct | 106 ms | 19364 KB | Ok |
71 | Correct | 94 ms | 18884 KB | Ok |
72 | Correct | 102 ms | 19476 KB | Ok |
73 | Correct | 129 ms | 20044 KB | Ok |
74 | Correct | 114 ms | 19264 KB | Ok |
75 | Correct | 141 ms | 20056 KB | Ok |
76 | Correct | 122 ms | 19892 KB | Ok |
77 | Correct | 115 ms | 19632 KB | Ok |
78 | Correct | 108 ms | 19336 KB | Ok |
79 | Correct | 115 ms | 19736 KB | Ok |
80 | Correct | 266 ms | 29280 KB | Ok |
81 | Correct | 255 ms | 29752 KB | Ok |
82 | Correct | 261 ms | 29160 KB | Ok |
83 | Correct | 258 ms | 29288 KB | Ok |
84 | Correct | 245 ms | 28520 KB | Ok |
85 | Correct | 262 ms | 28136 KB | Ok |
86 | Correct | 260 ms | 28400 KB | Ok |
87 | Correct | 257 ms | 29388 KB | Ok |
88 | Correct | 268 ms | 27872 KB | Ok |
89 | Correct | 272 ms | 28140 KB | Ok |
90 | Correct | 272 ms | 28904 KB | Ok |
91 | Correct | 264 ms | 29160 KB | Ok |
92 | Correct | 280 ms | 28276 KB | Ok |
93 | Correct | 269 ms | 28776 KB | Ok |
94 | Correct | 260 ms | 28392 KB | Ok |
95 | Correct | 279 ms | 28224 KB | Ok |
96 | Correct | 405 ms | 34012 KB | Ok |
97 | Correct | 364 ms | 30760 KB | Ok |
98 | Correct | 252 ms | 30664 KB | Ok |
99 | Correct | 294 ms | 30356 KB | Ok |
100 | Correct | 321 ms | 30952 KB | Ok |
101 | Correct | 355 ms | 32628 KB | Ok |
102 | Correct | 522 ms | 30920 KB | Ok |
103 | Correct | 316 ms | 31800 KB | Ok |
104 | Correct | 395 ms | 33476 KB | Ok |
105 | Correct | 391 ms | 34264 KB | Ok |
106 | Correct | 337 ms | 34076 KB | Ok |
107 | Correct | 393 ms | 33092 KB | Ok |
108 | Correct | 408 ms | 33844 KB | Ok |
109 | Correct | 427 ms | 35008 KB | Ok |
110 | Correct | 1695 ms | 72856 KB | Ok |
111 | Execution timed out | 2029 ms | 74912 KB | Time limit exceeded |
112 | Halted | 0 ms | 0 KB | - |