# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173803 | 2020-01-05T12:51:03 Z | davitmarg | Nice sequence (IZhO18_sequence) | C++17 | 2000 ms | 50412 KB |
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <unordered_map> #include <set> #include <queue> #include <iomanip> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; const int N = 200005; int gcd(int a, int b) { if (!a || !b) return a + b; return gcd(b, a % b); } LL lca(LL a, LL b) { return a * b / gcd(a, b); } int q, n, m, k; vector<int> t, a, used, tin; vector<vector<int>> g; inline void dfs(int v) { used[v] = 1; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (used[to]) continue; dfs(to); } //tin[v] = -t.size(); t.PB(v); } bool check(int x) { t.clear(); a.resize(x + 2); used.resize(x + 2); //tin.resize(x + 2); g.resize(x + 2); for (int i = 0; i <= x; i++) { g[i].clear(); used[i] = 0; a[i] = i; } for (int i = 0; i <= x; i++) { if (i - m >= 0) g[i - m].PB(i); if (i + n <= x) g[i + n].PB(i); } for (int i = 0; i <= x; i++) if (!used[i]) dfs(i); reverse(all(t)); //cout << "!!!!!" << x << endl; for (int i = 0; i < t.size(); i++) { int v = t[i]; for (int j = 0; j < g[v].size(); j++) { int to = g[v][j]; // if (tin[to] <= tin[v]) // return 0; //cout << v << " : " << to << endl; a[to] = max(a[to], a[v] + 1); } } return 1; } int main() { cin >> q; while (q--) { k = 0; cin >> n >> m; LL l, r, mid; l = 0; r = min(lca(n, m) - 1ll, 400000ll); // while (l <= r) // { // mid = (l + r) / 2; // if (check(mid)) // { // k = mid; // l = mid + 1; // } // else // r = mid - 1; // } k = n + m - gcd(n, m) - 1; check(k); cout << k << endl; for (int i = 1; i <= k; i++) printf("%d ", a[i] - a[i - 1]); cout << endl; } return 0; } /* 4 3 1 2 3 1 1 2 2 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 252 KB | Ok |
3 | Correct | 2 ms | 376 KB | Ok |
4 | Correct | 9 ms | 376 KB | Ok |
5 | Correct | 2 ms | 504 KB | Ok |
6 | Correct | 2 ms | 256 KB | Ok |
7 | Correct | 2 ms | 376 KB | Ok |
8 | Correct | 3 ms | 376 KB | Ok |
9 | Correct | 2 ms | 256 KB | Ok |
10 | Correct | 2 ms | 376 KB | Ok |
11 | Correct | 3 ms | 256 KB | Ok |
12 | Correct | 2 ms | 256 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 256 KB | Ok |
2 | Correct | 2 ms | 256 KB | Ok |
3 | Correct | 2 ms | 256 KB | Ok |
4 | Correct | 2 ms | 256 KB | Ok |
5 | Correct | 2 ms | 404 KB | Ok |
6 | Correct | 4 ms | 632 KB | Ok |
7 | Correct | 13 ms | 1452 KB | Ok |
8 | Correct | 7 ms | 888 KB | Ok |
9 | Correct | 15 ms | 1676 KB | Ok |
10 | Correct | 9 ms | 1140 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Ok |
2 | Correct | 2 ms | 376 KB | Ok |
3 | Correct | 2 ms | 256 KB | Ok |
4 | Correct | 2 ms | 256 KB | Ok |
5 | Correct | 2 ms | 256 KB | Ok |
6 | Correct | 0 ms | 376 KB | Ok |
7 | Correct | 2 ms | 256 KB | Ok |
8 | Correct | 2 ms | 256 KB | Ok |
9 | Correct | 2 ms | 376 KB | Ok |
10 | Correct | 2 ms | 256 KB | Ok |
11 | Correct | 2 ms | 256 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 348 KB | Ok |
2 | Correct | 2 ms | 376 KB | Ok |
3 | Correct | 2 ms | 256 KB | Ok |
4 | Correct | 2 ms | 256 KB | Ok |
5 | Correct | 2 ms | 256 KB | Ok |
6 | Correct | 143 ms | 17084 KB | Ok |
7 | Correct | 117 ms | 18820 KB | Ok |
8 | Correct | 205 ms | 20596 KB | Ok |
9 | Correct | 184 ms | 18012 KB | Ok |
10 | Correct | 106 ms | 12244 KB | Ok |
11 | Correct | 166 ms | 20724 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 252 KB | Ok |
3 | Correct | 2 ms | 376 KB | Ok |
4 | Correct | 9 ms | 376 KB | Ok |
5 | Correct | 2 ms | 504 KB | Ok |
6 | Correct | 2 ms | 256 KB | Ok |
7 | Correct | 2 ms | 376 KB | Ok |
8 | Correct | 3 ms | 376 KB | Ok |
9 | Correct | 2 ms | 256 KB | Ok |
10 | Correct | 2 ms | 376 KB | Ok |
11 | Correct | 3 ms | 256 KB | Ok |
12 | Correct | 2 ms | 256 KB | Ok |
13 | Correct | 2 ms | 256 KB | Ok |
14 | Correct | 2 ms | 376 KB | Ok |
15 | Correct | 2 ms | 256 KB | Ok |
16 | Correct | 2 ms | 256 KB | Ok |
17 | Correct | 2 ms | 256 KB | Ok |
18 | Correct | 0 ms | 376 KB | Ok |
19 | Correct | 2 ms | 256 KB | Ok |
20 | Correct | 2 ms | 256 KB | Ok |
21 | Correct | 2 ms | 376 KB | Ok |
22 | Correct | 2 ms | 256 KB | Ok |
23 | Correct | 2 ms | 256 KB | Ok |
24 | Correct | 4 ms | 504 KB | Ok |
25 | Correct | 6 ms | 632 KB | Ok |
26 | Correct | 5 ms | 632 KB | Ok |
27 | Correct | 4 ms | 632 KB | Ok |
28 | Correct | 9 ms | 504 KB | Ok |
29 | Correct | 4 ms | 632 KB | Ok |
30 | Correct | 4 ms | 504 KB | Ok |
31 | Correct | 4 ms | 504 KB | Ok |
32 | Correct | 5 ms | 632 KB | Ok |
33 | Correct | 4 ms | 632 KB | Ok |
34 | Correct | 7 ms | 888 KB | Ok |
35 | Correct | 7 ms | 760 KB | Ok |
36 | Correct | 8 ms | 888 KB | Ok |
37 | Correct | 8 ms | 888 KB | Ok |
38 | Correct | 8 ms | 888 KB | Ok |
39 | Correct | 9 ms | 760 KB | Ok |
40 | Correct | 9 ms | 888 KB | Ok |
41 | Correct | 9 ms | 760 KB | Ok |
42 | Correct | 5 ms | 760 KB | Ok |
43 | Correct | 8 ms | 892 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 252 KB | Ok |
3 | Correct | 2 ms | 376 KB | Ok |
4 | Correct | 9 ms | 376 KB | Ok |
5 | Correct | 2 ms | 504 KB | Ok |
6 | Correct | 2 ms | 256 KB | Ok |
7 | Correct | 2 ms | 376 KB | Ok |
8 | Correct | 3 ms | 376 KB | Ok |
9 | Correct | 2 ms | 256 KB | Ok |
10 | Correct | 2 ms | 376 KB | Ok |
11 | Correct | 3 ms | 256 KB | Ok |
12 | Correct | 2 ms | 256 KB | Ok |
13 | Correct | 6 ms | 256 KB | Ok |
14 | Correct | 2 ms | 256 KB | Ok |
15 | Correct | 2 ms | 256 KB | Ok |
16 | Correct | 2 ms | 256 KB | Ok |
17 | Correct | 2 ms | 404 KB | Ok |
18 | Correct | 4 ms | 632 KB | Ok |
19 | Correct | 13 ms | 1452 KB | Ok |
20 | Correct | 7 ms | 888 KB | Ok |
21 | Correct | 15 ms | 1676 KB | Ok |
22 | Correct | 9 ms | 1140 KB | Ok |
23 | Correct | 2 ms | 256 KB | Ok |
24 | Correct | 2 ms | 376 KB | Ok |
25 | Correct | 2 ms | 256 KB | Ok |
26 | Correct | 2 ms | 256 KB | Ok |
27 | Correct | 2 ms | 256 KB | Ok |
28 | Correct | 0 ms | 376 KB | Ok |
29 | Correct | 2 ms | 256 KB | Ok |
30 | Correct | 2 ms | 256 KB | Ok |
31 | Correct | 2 ms | 376 KB | Ok |
32 | Correct | 2 ms | 256 KB | Ok |
33 | Correct | 2 ms | 256 KB | Ok |
34 | Correct | 4 ms | 504 KB | Ok |
35 | Correct | 6 ms | 632 KB | Ok |
36 | Correct | 5 ms | 632 KB | Ok |
37 | Correct | 4 ms | 632 KB | Ok |
38 | Correct | 9 ms | 504 KB | Ok |
39 | Correct | 4 ms | 632 KB | Ok |
40 | Correct | 4 ms | 504 KB | Ok |
41 | Correct | 4 ms | 504 KB | Ok |
42 | Correct | 5 ms | 632 KB | Ok |
43 | Correct | 4 ms | 632 KB | Ok |
44 | Correct | 7 ms | 888 KB | Ok |
45 | Correct | 7 ms | 760 KB | Ok |
46 | Correct | 8 ms | 888 KB | Ok |
47 | Correct | 8 ms | 888 KB | Ok |
48 | Correct | 8 ms | 888 KB | Ok |
49 | Correct | 9 ms | 760 KB | Ok |
50 | Correct | 9 ms | 888 KB | Ok |
51 | Correct | 9 ms | 760 KB | Ok |
52 | Correct | 5 ms | 760 KB | Ok |
53 | Correct | 8 ms | 892 KB | Ok |
54 | Correct | 102 ms | 8680 KB | Ok |
55 | Correct | 108 ms | 8036 KB | Ok |
56 | Correct | 105 ms | 8172 KB | Ok |
57 | Correct | 82 ms | 7408 KB | Ok |
58 | Correct | 105 ms | 8592 KB | Ok |
59 | Correct | 106 ms | 7412 KB | Ok |
60 | Correct | 92 ms | 7148 KB | Ok |
61 | Correct | 86 ms | 8060 KB | Ok |
62 | Correct | 122 ms | 8016 KB | Ok |
63 | Correct | 94 ms | 7252 KB | Ok |
64 | Correct | 111 ms | 7924 KB | Ok |
65 | Correct | 124 ms | 8180 KB | Ok |
66 | Correct | 91 ms | 7640 KB | Ok |
67 | Correct | 104 ms | 7836 KB | Ok |
68 | Correct | 132 ms | 7820 KB | Ok |
69 | Correct | 388 ms | 14276 KB | Ok |
70 | Correct | 326 ms | 15328 KB | Ok |
71 | Correct | 268 ms | 12600 KB | Ok |
72 | Correct | 307 ms | 14648 KB | Ok |
73 | Correct | 592 ms | 12988 KB | Ok |
74 | Correct | 271 ms | 12476 KB | Ok |
75 | Correct | 440 ms | 12776 KB | Ok |
76 | Correct | 273 ms | 15112 KB | Ok |
77 | Correct | 253 ms | 11976 KB | Ok |
78 | Correct | 271 ms | 15168 KB | Ok |
79 | Correct | 298 ms | 13972 KB | Ok |
80 | Correct | 273 ms | 13368 KB | Ok |
81 | Correct | 526 ms | 14580 KB | Ok |
82 | Correct | 333 ms | 13712 KB | Ok |
83 | Correct | 245 ms | 13112 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 252 KB | Ok |
3 | Correct | 2 ms | 376 KB | Ok |
4 | Correct | 9 ms | 376 KB | Ok |
5 | Correct | 2 ms | 504 KB | Ok |
6 | Correct | 2 ms | 256 KB | Ok |
7 | Correct | 2 ms | 376 KB | Ok |
8 | Correct | 3 ms | 376 KB | Ok |
9 | Correct | 2 ms | 256 KB | Ok |
10 | Correct | 2 ms | 376 KB | Ok |
11 | Correct | 3 ms | 256 KB | Ok |
12 | Correct | 2 ms | 256 KB | Ok |
13 | Correct | 6 ms | 256 KB | Ok |
14 | Correct | 2 ms | 256 KB | Ok |
15 | Correct | 2 ms | 256 KB | Ok |
16 | Correct | 2 ms | 256 KB | Ok |
17 | Correct | 2 ms | 404 KB | Ok |
18 | Correct | 4 ms | 632 KB | Ok |
19 | Correct | 13 ms | 1452 KB | Ok |
20 | Correct | 7 ms | 888 KB | Ok |
21 | Correct | 15 ms | 1676 KB | Ok |
22 | Correct | 9 ms | 1140 KB | Ok |
23 | Correct | 2 ms | 256 KB | Ok |
24 | Correct | 2 ms | 376 KB | Ok |
25 | Correct | 2 ms | 256 KB | Ok |
26 | Correct | 2 ms | 256 KB | Ok |
27 | Correct | 2 ms | 256 KB | Ok |
28 | Correct | 0 ms | 376 KB | Ok |
29 | Correct | 2 ms | 256 KB | Ok |
30 | Correct | 2 ms | 256 KB | Ok |
31 | Correct | 2 ms | 376 KB | Ok |
32 | Correct | 2 ms | 256 KB | Ok |
33 | Correct | 2 ms | 256 KB | Ok |
34 | Correct | 9 ms | 348 KB | Ok |
35 | Correct | 2 ms | 376 KB | Ok |
36 | Correct | 2 ms | 256 KB | Ok |
37 | Correct | 2 ms | 256 KB | Ok |
38 | Correct | 2 ms | 256 KB | Ok |
39 | Correct | 143 ms | 17084 KB | Ok |
40 | Correct | 117 ms | 18820 KB | Ok |
41 | Correct | 205 ms | 20596 KB | Ok |
42 | Correct | 184 ms | 18012 KB | Ok |
43 | Correct | 106 ms | 12244 KB | Ok |
44 | Correct | 166 ms | 20724 KB | Ok |
45 | Correct | 4 ms | 504 KB | Ok |
46 | Correct | 6 ms | 632 KB | Ok |
47 | Correct | 5 ms | 632 KB | Ok |
48 | Correct | 4 ms | 632 KB | Ok |
49 | Correct | 9 ms | 504 KB | Ok |
50 | Correct | 4 ms | 632 KB | Ok |
51 | Correct | 4 ms | 504 KB | Ok |
52 | Correct | 4 ms | 504 KB | Ok |
53 | Correct | 5 ms | 632 KB | Ok |
54 | Correct | 4 ms | 632 KB | Ok |
55 | Correct | 7 ms | 888 KB | Ok |
56 | Correct | 7 ms | 760 KB | Ok |
57 | Correct | 8 ms | 888 KB | Ok |
58 | Correct | 8 ms | 888 KB | Ok |
59 | Correct | 8 ms | 888 KB | Ok |
60 | Correct | 9 ms | 760 KB | Ok |
61 | Correct | 9 ms | 888 KB | Ok |
62 | Correct | 9 ms | 760 KB | Ok |
63 | Correct | 5 ms | 760 KB | Ok |
64 | Correct | 8 ms | 892 KB | Ok |
65 | Correct | 102 ms | 8680 KB | Ok |
66 | Correct | 108 ms | 8036 KB | Ok |
67 | Correct | 105 ms | 8172 KB | Ok |
68 | Correct | 82 ms | 7408 KB | Ok |
69 | Correct | 105 ms | 8592 KB | Ok |
70 | Correct | 106 ms | 7412 KB | Ok |
71 | Correct | 92 ms | 7148 KB | Ok |
72 | Correct | 86 ms | 8060 KB | Ok |
73 | Correct | 122 ms | 8016 KB | Ok |
74 | Correct | 94 ms | 7252 KB | Ok |
75 | Correct | 111 ms | 7924 KB | Ok |
76 | Correct | 124 ms | 8180 KB | Ok |
77 | Correct | 91 ms | 7640 KB | Ok |
78 | Correct | 104 ms | 7836 KB | Ok |
79 | Correct | 132 ms | 7820 KB | Ok |
80 | Correct | 388 ms | 14276 KB | Ok |
81 | Correct | 326 ms | 15328 KB | Ok |
82 | Correct | 268 ms | 12600 KB | Ok |
83 | Correct | 307 ms | 14648 KB | Ok |
84 | Correct | 592 ms | 12988 KB | Ok |
85 | Correct | 271 ms | 12476 KB | Ok |
86 | Correct | 440 ms | 12776 KB | Ok |
87 | Correct | 273 ms | 15112 KB | Ok |
88 | Correct | 253 ms | 11976 KB | Ok |
89 | Correct | 271 ms | 15168 KB | Ok |
90 | Correct | 298 ms | 13972 KB | Ok |
91 | Correct | 273 ms | 13368 KB | Ok |
92 | Correct | 526 ms | 14580 KB | Ok |
93 | Correct | 333 ms | 13712 KB | Ok |
94 | Correct | 245 ms | 13112 KB | Ok |
95 | Correct | 304 ms | 19744 KB | Ok |
96 | Correct | 486 ms | 29036 KB | Ok |
97 | Correct | 439 ms | 23784 KB | Ok |
98 | Correct | 310 ms | 24508 KB | Ok |
99 | Correct | 318 ms | 23484 KB | Ok |
100 | Correct | 383 ms | 22876 KB | Ok |
101 | Correct | 329 ms | 27068 KB | Ok |
102 | Correct | 482 ms | 26420 KB | Ok |
103 | Correct | 378 ms | 29204 KB | Ok |
104 | Correct | 427 ms | 32900 KB | Ok |
105 | Correct | 466 ms | 34208 KB | Ok |
106 | Correct | 374 ms | 28708 KB | Ok |
107 | Correct | 417 ms | 27372 KB | Ok |
108 | Correct | 497 ms | 34316 KB | Ok |
109 | Correct | 434 ms | 30060 KB | Ok |
110 | Execution timed out | 2076 ms | 50412 KB | Time limit exceeded |
111 | Halted | 0 ms | 0 KB | - |