# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173825 | 2020-01-05T13:28:16 Z | davitmarg | Nice sequence (IZhO18_sequence) | C++17 | 2000 ms | 100128 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 = 10 * 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, a[N], used[N], tin[N]; vector<int> t, g[N]; 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(); for (int i = 0; i <= x; i++) g[i].clear(); 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); //cout << "!!!!!" << x << endl; int v, to; for (int i = t.size() - 1; i >= 0; i--) { v = t[i]; a[v] = t.size() - i; for (int j = 0; j < g[v].size(); j++) { 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; } char uu[12]; void tp(int x) { if (x == 0) { putchar('0'); return; } if (x < 0) { putchar('-'); x *= (-1); } int i = 0; while (x) { uu[i++] = (x % 10) + '0'; x /= 10; } for (i = i - 1; i >= 0; --i) putchar(uu[i]); } int main() { cin >> q; while (q--) { k = 0; scanf("%d%d", &n, &m); LL l, r, mid; l = 0; r = n + m - 1; // 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); tp(k); putchar('\n'); for (int i = 1; i <= k; i++) { //printf("%d ", a[i] - a[i - 1]); tp(a[i] - a[i - 1]); putchar(' '); used[i] = 0; } used[0] = 0; putchar('\n'); } return 0; } /* 4 3 1 2 3 1 1 2 2 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47352 KB | Ok |
2 | Correct | 44 ms | 47352 KB | Ok |
3 | Correct | 44 ms | 47392 KB | Ok |
4 | Correct | 44 ms | 47352 KB | Ok |
5 | Correct | 44 ms | 47352 KB | Ok |
6 | Correct | 44 ms | 47352 KB | Ok |
7 | Correct | 50 ms | 47364 KB | Ok |
8 | Correct | 45 ms | 47272 KB | Ok |
9 | Correct | 45 ms | 47332 KB | Ok |
10 | Correct | 44 ms | 47352 KB | Ok |
11 | Correct | 45 ms | 47320 KB | Ok |
12 | Correct | 44 ms | 47228 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47352 KB | Ok |
2 | Correct | 44 ms | 47224 KB | Ok |
3 | Correct | 45 ms | 47360 KB | Ok |
4 | Correct | 45 ms | 47356 KB | Ok |
5 | Correct | 44 ms | 47360 KB | Ok |
6 | Correct | 47 ms | 47452 KB | Ok |
7 | Correct | 56 ms | 48248 KB | Ok |
8 | Correct | 50 ms | 47680 KB | Ok |
9 | Correct | 61 ms | 48556 KB | Ok |
10 | Correct | 52 ms | 47896 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47440 KB | Ok |
2 | Correct | 45 ms | 47352 KB | Ok |
3 | Correct | 51 ms | 47352 KB | Ok |
4 | Correct | 45 ms | 47264 KB | Ok |
5 | Correct | 45 ms | 47244 KB | Ok |
6 | Correct | 44 ms | 47352 KB | Ok |
7 | Correct | 45 ms | 47332 KB | Ok |
8 | Correct | 44 ms | 47224 KB | Ok |
9 | Correct | 46 ms | 47228 KB | Ok |
10 | Correct | 44 ms | 47352 KB | Ok |
11 | Correct | 55 ms | 47224 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47324 KB | Ok |
2 | Correct | 44 ms | 47224 KB | Ok |
3 | Correct | 44 ms | 47352 KB | Ok |
4 | Correct | 44 ms | 47300 KB | Ok |
5 | Correct | 45 ms | 47464 KB | Ok |
6 | Correct | 175 ms | 62952 KB | Ok |
7 | Correct | 131 ms | 62448 KB | Ok |
8 | Correct | 212 ms | 65704 KB | Ok |
9 | Correct | 220 ms | 62972 KB | Ok |
10 | Correct | 135 ms | 58128 KB | Ok |
11 | Correct | 203 ms | 66924 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47352 KB | Ok |
2 | Correct | 44 ms | 47352 KB | Ok |
3 | Correct | 44 ms | 47392 KB | Ok |
4 | Correct | 44 ms | 47352 KB | Ok |
5 | Correct | 44 ms | 47352 KB | Ok |
6 | Correct | 44 ms | 47352 KB | Ok |
7 | Correct | 50 ms | 47364 KB | Ok |
8 | Correct | 45 ms | 47272 KB | Ok |
9 | Correct | 45 ms | 47332 KB | Ok |
10 | Correct | 44 ms | 47352 KB | Ok |
11 | Correct | 45 ms | 47320 KB | Ok |
12 | Correct | 44 ms | 47228 KB | Ok |
13 | Correct | 45 ms | 47440 KB | Ok |
14 | Correct | 45 ms | 47352 KB | Ok |
15 | Correct | 51 ms | 47352 KB | Ok |
16 | Correct | 45 ms | 47264 KB | Ok |
17 | Correct | 45 ms | 47244 KB | Ok |
18 | Correct | 44 ms | 47352 KB | Ok |
19 | Correct | 45 ms | 47332 KB | Ok |
20 | Correct | 44 ms | 47224 KB | Ok |
21 | Correct | 46 ms | 47228 KB | Ok |
22 | Correct | 44 ms | 47352 KB | Ok |
23 | Correct | 55 ms | 47224 KB | Ok |
24 | Correct | 46 ms | 47476 KB | Ok |
25 | Correct | 46 ms | 47552 KB | Ok |
26 | Correct | 48 ms | 47484 KB | Ok |
27 | Correct | 46 ms | 47480 KB | Ok |
28 | Correct | 46 ms | 47608 KB | Ok |
29 | Correct | 47 ms | 47444 KB | Ok |
30 | Correct | 47 ms | 47480 KB | Ok |
31 | Correct | 47 ms | 47516 KB | Ok |
32 | Correct | 47 ms | 47504 KB | Ok |
33 | Correct | 46 ms | 47480 KB | Ok |
34 | Correct | 50 ms | 47736 KB | Ok |
35 | Correct | 50 ms | 47764 KB | Ok |
36 | Correct | 50 ms | 47736 KB | Ok |
37 | Correct | 50 ms | 47736 KB | Ok |
38 | Correct | 50 ms | 47736 KB | Ok |
39 | Correct | 49 ms | 47608 KB | Ok |
40 | Correct | 50 ms | 47772 KB | Ok |
41 | Correct | 50 ms | 47656 KB | Ok |
42 | Correct | 51 ms | 47736 KB | Ok |
43 | Correct | 49 ms | 47740 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47352 KB | Ok |
2 | Correct | 44 ms | 47352 KB | Ok |
3 | Correct | 44 ms | 47392 KB | Ok |
4 | Correct | 44 ms | 47352 KB | Ok |
5 | Correct | 44 ms | 47352 KB | Ok |
6 | Correct | 44 ms | 47352 KB | Ok |
7 | Correct | 50 ms | 47364 KB | Ok |
8 | Correct | 45 ms | 47272 KB | Ok |
9 | Correct | 45 ms | 47332 KB | Ok |
10 | Correct | 44 ms | 47352 KB | Ok |
11 | Correct | 45 ms | 47320 KB | Ok |
12 | Correct | 44 ms | 47228 KB | Ok |
13 | Correct | 45 ms | 47352 KB | Ok |
14 | Correct | 44 ms | 47224 KB | Ok |
15 | Correct | 45 ms | 47360 KB | Ok |
16 | Correct | 45 ms | 47356 KB | Ok |
17 | Correct | 44 ms | 47360 KB | Ok |
18 | Correct | 47 ms | 47452 KB | Ok |
19 | Correct | 56 ms | 48248 KB | Ok |
20 | Correct | 50 ms | 47680 KB | Ok |
21 | Correct | 61 ms | 48556 KB | Ok |
22 | Correct | 52 ms | 47896 KB | Ok |
23 | Correct | 45 ms | 47440 KB | Ok |
24 | Correct | 45 ms | 47352 KB | Ok |
25 | Correct | 51 ms | 47352 KB | Ok |
26 | Correct | 45 ms | 47264 KB | Ok |
27 | Correct | 45 ms | 47244 KB | Ok |
28 | Correct | 44 ms | 47352 KB | Ok |
29 | Correct | 45 ms | 47332 KB | Ok |
30 | Correct | 44 ms | 47224 KB | Ok |
31 | Correct | 46 ms | 47228 KB | Ok |
32 | Correct | 44 ms | 47352 KB | Ok |
33 | Correct | 55 ms | 47224 KB | Ok |
34 | Correct | 46 ms | 47476 KB | Ok |
35 | Correct | 46 ms | 47552 KB | Ok |
36 | Correct | 48 ms | 47484 KB | Ok |
37 | Correct | 46 ms | 47480 KB | Ok |
38 | Correct | 46 ms | 47608 KB | Ok |
39 | Correct | 47 ms | 47444 KB | Ok |
40 | Correct | 47 ms | 47480 KB | Ok |
41 | Correct | 47 ms | 47516 KB | Ok |
42 | Correct | 47 ms | 47504 KB | Ok |
43 | Correct | 46 ms | 47480 KB | Ok |
44 | Correct | 50 ms | 47736 KB | Ok |
45 | Correct | 50 ms | 47764 KB | Ok |
46 | Correct | 50 ms | 47736 KB | Ok |
47 | Correct | 50 ms | 47736 KB | Ok |
48 | Correct | 50 ms | 47736 KB | Ok |
49 | Correct | 49 ms | 47608 KB | Ok |
50 | Correct | 50 ms | 47772 KB | Ok |
51 | Correct | 50 ms | 47656 KB | Ok |
52 | Correct | 51 ms | 47736 KB | Ok |
53 | Correct | 49 ms | 47740 KB | Ok |
54 | Correct | 119 ms | 53384 KB | Ok |
55 | Correct | 129 ms | 53872 KB | Ok |
56 | Correct | 132 ms | 53824 KB | Ok |
57 | Correct | 103 ms | 52748 KB | Ok |
58 | Correct | 128 ms | 53700 KB | Ok |
59 | Correct | 123 ms | 53360 KB | Ok |
60 | Correct | 114 ms | 52772 KB | Ok |
61 | Correct | 107 ms | 53228 KB | Ok |
62 | Correct | 144 ms | 54180 KB | Ok |
63 | Correct | 124 ms | 53016 KB | Ok |
64 | Correct | 142 ms | 53872 KB | Ok |
65 | Correct | 131 ms | 53872 KB | Ok |
66 | Correct | 112 ms | 53276 KB | Ok |
67 | Correct | 111 ms | 52976 KB | Ok |
68 | Correct | 140 ms | 53544 KB | Ok |
69 | Correct | 348 ms | 60856 KB | Ok |
70 | Correct | 400 ms | 60912 KB | Ok |
71 | Correct | 344 ms | 59576 KB | Ok |
72 | Correct | 327 ms | 60896 KB | Ok |
73 | Correct | 349 ms | 59688 KB | Ok |
74 | Correct | 351 ms | 60144 KB | Ok |
75 | Correct | 359 ms | 60532 KB | Ok |
76 | Correct | 346 ms | 60916 KB | Ok |
77 | Correct | 356 ms | 60020 KB | Ok |
78 | Correct | 366 ms | 61044 KB | Ok |
79 | Correct | 377 ms | 60624 KB | Ok |
80 | Correct | 321 ms | 59724 KB | Ok |
81 | Correct | 335 ms | 60860 KB | Ok |
82 | Correct | 344 ms | 60360 KB | Ok |
83 | Correct | 356 ms | 60916 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47352 KB | Ok |
2 | Correct | 44 ms | 47352 KB | Ok |
3 | Correct | 44 ms | 47392 KB | Ok |
4 | Correct | 44 ms | 47352 KB | Ok |
5 | Correct | 44 ms | 47352 KB | Ok |
6 | Correct | 44 ms | 47352 KB | Ok |
7 | Correct | 50 ms | 47364 KB | Ok |
8 | Correct | 45 ms | 47272 KB | Ok |
9 | Correct | 45 ms | 47332 KB | Ok |
10 | Correct | 44 ms | 47352 KB | Ok |
11 | Correct | 45 ms | 47320 KB | Ok |
12 | Correct | 44 ms | 47228 KB | Ok |
13 | Correct | 45 ms | 47352 KB | Ok |
14 | Correct | 44 ms | 47224 KB | Ok |
15 | Correct | 45 ms | 47360 KB | Ok |
16 | Correct | 45 ms | 47356 KB | Ok |
17 | Correct | 44 ms | 47360 KB | Ok |
18 | Correct | 47 ms | 47452 KB | Ok |
19 | Correct | 56 ms | 48248 KB | Ok |
20 | Correct | 50 ms | 47680 KB | Ok |
21 | Correct | 61 ms | 48556 KB | Ok |
22 | Correct | 52 ms | 47896 KB | Ok |
23 | Correct | 45 ms | 47440 KB | Ok |
24 | Correct | 45 ms | 47352 KB | Ok |
25 | Correct | 51 ms | 47352 KB | Ok |
26 | Correct | 45 ms | 47264 KB | Ok |
27 | Correct | 45 ms | 47244 KB | Ok |
28 | Correct | 44 ms | 47352 KB | Ok |
29 | Correct | 45 ms | 47332 KB | Ok |
30 | Correct | 44 ms | 47224 KB | Ok |
31 | Correct | 46 ms | 47228 KB | Ok |
32 | Correct | 44 ms | 47352 KB | Ok |
33 | Correct | 55 ms | 47224 KB | Ok |
34 | Correct | 45 ms | 47324 KB | Ok |
35 | Correct | 44 ms | 47224 KB | Ok |
36 | Correct | 44 ms | 47352 KB | Ok |
37 | Correct | 44 ms | 47300 KB | Ok |
38 | Correct | 45 ms | 47464 KB | Ok |
39 | Correct | 175 ms | 62952 KB | Ok |
40 | Correct | 131 ms | 62448 KB | Ok |
41 | Correct | 212 ms | 65704 KB | Ok |
42 | Correct | 220 ms | 62972 KB | Ok |
43 | Correct | 135 ms | 58128 KB | Ok |
44 | Correct | 203 ms | 66924 KB | Ok |
45 | Correct | 46 ms | 47476 KB | Ok |
46 | Correct | 46 ms | 47552 KB | Ok |
47 | Correct | 48 ms | 47484 KB | Ok |
48 | Correct | 46 ms | 47480 KB | Ok |
49 | Correct | 46 ms | 47608 KB | Ok |
50 | Correct | 47 ms | 47444 KB | Ok |
51 | Correct | 47 ms | 47480 KB | Ok |
52 | Correct | 47 ms | 47516 KB | Ok |
53 | Correct | 47 ms | 47504 KB | Ok |
54 | Correct | 46 ms | 47480 KB | Ok |
55 | Correct | 50 ms | 47736 KB | Ok |
56 | Correct | 50 ms | 47764 KB | Ok |
57 | Correct | 50 ms | 47736 KB | Ok |
58 | Correct | 50 ms | 47736 KB | Ok |
59 | Correct | 50 ms | 47736 KB | Ok |
60 | Correct | 49 ms | 47608 KB | Ok |
61 | Correct | 50 ms | 47772 KB | Ok |
62 | Correct | 50 ms | 47656 KB | Ok |
63 | Correct | 51 ms | 47736 KB | Ok |
64 | Correct | 49 ms | 47740 KB | Ok |
65 | Correct | 119 ms | 53384 KB | Ok |
66 | Correct | 129 ms | 53872 KB | Ok |
67 | Correct | 132 ms | 53824 KB | Ok |
68 | Correct | 103 ms | 52748 KB | Ok |
69 | Correct | 128 ms | 53700 KB | Ok |
70 | Correct | 123 ms | 53360 KB | Ok |
71 | Correct | 114 ms | 52772 KB | Ok |
72 | Correct | 107 ms | 53228 KB | Ok |
73 | Correct | 144 ms | 54180 KB | Ok |
74 | Correct | 124 ms | 53016 KB | Ok |
75 | Correct | 142 ms | 53872 KB | Ok |
76 | Correct | 131 ms | 53872 KB | Ok |
77 | Correct | 112 ms | 53276 KB | Ok |
78 | Correct | 111 ms | 52976 KB | Ok |
79 | Correct | 140 ms | 53544 KB | Ok |
80 | Correct | 348 ms | 60856 KB | Ok |
81 | Correct | 400 ms | 60912 KB | Ok |
82 | Correct | 344 ms | 59576 KB | Ok |
83 | Correct | 327 ms | 60896 KB | Ok |
84 | Correct | 349 ms | 59688 KB | Ok |
85 | Correct | 351 ms | 60144 KB | Ok |
86 | Correct | 359 ms | 60532 KB | Ok |
87 | Correct | 346 ms | 60916 KB | Ok |
88 | Correct | 356 ms | 60020 KB | Ok |
89 | Correct | 366 ms | 61044 KB | Ok |
90 | Correct | 377 ms | 60624 KB | Ok |
91 | Correct | 321 ms | 59724 KB | Ok |
92 | Correct | 335 ms | 60860 KB | Ok |
93 | Correct | 344 ms | 60360 KB | Ok |
94 | Correct | 356 ms | 60916 KB | Ok |
95 | Correct | 261 ms | 63324 KB | Ok |
96 | Correct | 439 ms | 71076 KB | Ok |
97 | Correct | 394 ms | 67104 KB | Ok |
98 | Correct | 288 ms | 66816 KB | Ok |
99 | Correct | 279 ms | 66376 KB | Ok |
100 | Correct | 385 ms | 66660 KB | Ok |
101 | Correct | 306 ms | 68808 KB | Ok |
102 | Correct | 372 ms | 67140 KB | Ok |
103 | Correct | 385 ms | 68560 KB | Ok |
104 | Correct | 412 ms | 70120 KB | Ok |
105 | Correct | 462 ms | 70732 KB | Ok |
106 | Correct | 345 ms | 69708 KB | Ok |
107 | Correct | 388 ms | 69604 KB | Ok |
108 | Correct | 483 ms | 70872 KB | Ok |
109 | Correct | 402 ms | 71120 KB | Ok |
110 | Execution timed out | 2064 ms | 100128 KB | Time limit exceeded |
111 | Halted | 0 ms | 0 KB | - |