# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497792 | 2021-12-23T20:09:31 Z | Ziel | Nice sequence (IZhO18_sequence) | C++11 | 2000 ms | 66068 KB |
/** * LES GREATEABLES BRO TEAM **/ #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)x.size() const bool FLAG = true; void setIO(const string &f = ""); #define int ll const int N = 1e6 + 156; int was[N], visited[N]; vector<int> g[N], order; bool dfs(int v) { was[v] = 1; for (int to: g[v]) { if (!was[to]) { if (dfs(to)) return true; } else if (was[to] == 1) return true; } was[v] = 2; return false; } void dfs2(int v) { visited[v] = 1; for (int to: g[v]) { if (!visited[to]) dfs2(to); } order.push_back(v); } void solve() { int n, m; cin >> n >> m; int lo = 0, hi = n + m, res = -1; while (lo <= hi) { int mid = (lo + hi) / 2; for (int i = n; i <= mid; i++) g[i].push_back(i - n); for (int i = m; i <= mid; i++) g[i - m].push_back(i); bool have_cycle = false; for (int i = 0; i <= mid; i++) { if (!was[i] && dfs(i)) { have_cycle = true; break; } } for (int i = 0; i <= mid; i++) { was[i] = 0; if (sz(g[i])) g[i].clear(); } if (have_cycle) { hi = mid - 1; } else { lo = mid + 1; res = mid; } } cout << res << '\n'; for (int i = n; i <= res; i++) g[i].push_back(i - n); for (int i = m; i <= res; i++) g[i - m].push_back(i); for (int i = 0; i <= res; i++) { if (!visited[i]) dfs2(i); } reverse(order.begin(), order.end()); vector<int> p(sz(order)); for (int i = 0; i < sz(order); i++) { p[order[i]] = i; } int x = p[0]; for (int i = 0; i < sz(p); i++) p[i] -= x; for (int i = 1; i < sz(p); i++) cout << p[i] - p[i - 1] << ' '; order.clear(); for (int i = 0; i <= res; i++) { was[i] = 0; visited[i] = 0; g[i].clear(); } cout << '\n'; } /* 0 2 1 3 3 0 2 1 3 0 */ signed main() { setIO(); int tt = 1; if (FLAG) { cin >> tt; } while (tt--) { solve(); } return 0; } void setIO(const string &f) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen((f + ".in").c_str(), "r")) { freopen((f + ".in").c_str(), "r", stdin); freopen((f + ".out").c_str(), "w", stdout); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23756 KB | Ok |
2 | Correct | 15 ms | 23740 KB | Ok |
3 | Correct | 14 ms | 23784 KB | Ok |
4 | Correct | 22 ms | 23752 KB | Ok |
5 | Correct | 15 ms | 23808 KB | Ok |
6 | Correct | 14 ms | 23756 KB | Ok |
7 | Correct | 15 ms | 23800 KB | Ok |
8 | Correct | 14 ms | 23784 KB | Ok |
9 | Correct | 16 ms | 23756 KB | Ok |
10 | Correct | 15 ms | 23792 KB | Ok |
11 | Correct | 14 ms | 23756 KB | Ok |
12 | Correct | 14 ms | 23796 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23820 KB | Ok |
2 | Correct | 32 ms | 23776 KB | Ok |
3 | Correct | 14 ms | 23776 KB | Ok |
4 | Correct | 15 ms | 23756 KB | Ok |
5 | Correct | 14 ms | 23756 KB | Ok |
6 | Correct | 17 ms | 24012 KB | Ok |
7 | Correct | 36 ms | 25216 KB | Ok |
8 | Correct | 28 ms | 24400 KB | Ok |
9 | Correct | 43 ms | 25412 KB | Ok |
10 | Correct | 27 ms | 24608 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23736 KB | Ok |
2 | Correct | 13 ms | 23820 KB | Ok |
3 | Correct | 13 ms | 23756 KB | Ok |
4 | Correct | 16 ms | 23756 KB | Ok |
5 | Correct | 13 ms | 23776 KB | Ok |
6 | Correct | 16 ms | 23808 KB | Ok |
7 | Correct | 81 ms | 23700 KB | Ok |
8 | Correct | 26 ms | 23800 KB | Ok |
9 | Correct | 40 ms | 23736 KB | Ok |
10 | Correct | 13 ms | 23748 KB | Ok |
11 | Correct | 14 ms | 23708 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23812 KB | Ok |
2 | Correct | 15 ms | 23756 KB | Ok |
3 | Correct | 16 ms | 23812 KB | Ok |
4 | Correct | 17 ms | 23824 KB | Ok |
5 | Correct | 15 ms | 23808 KB | Ok |
6 | Correct | 473 ms | 44692 KB | Ok |
7 | Correct | 297 ms | 47072 KB | Ok |
8 | Correct | 755 ms | 50212 KB | Ok |
9 | Correct | 575 ms | 48464 KB | Ok |
10 | Correct | 288 ms | 38164 KB | Ok |
11 | Correct | 571 ms | 50160 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23756 KB | Ok |
2 | Correct | 15 ms | 23740 KB | Ok |
3 | Correct | 14 ms | 23784 KB | Ok |
4 | Correct | 22 ms | 23752 KB | Ok |
5 | Correct | 15 ms | 23808 KB | Ok |
6 | Correct | 14 ms | 23756 KB | Ok |
7 | Correct | 15 ms | 23800 KB | Ok |
8 | Correct | 14 ms | 23784 KB | Ok |
9 | Correct | 16 ms | 23756 KB | Ok |
10 | Correct | 15 ms | 23792 KB | Ok |
11 | Correct | 14 ms | 23756 KB | Ok |
12 | Correct | 14 ms | 23796 KB | Ok |
13 | Correct | 15 ms | 23736 KB | Ok |
14 | Correct | 13 ms | 23820 KB | Ok |
15 | Correct | 13 ms | 23756 KB | Ok |
16 | Correct | 16 ms | 23756 KB | Ok |
17 | Correct | 13 ms | 23776 KB | Ok |
18 | Correct | 16 ms | 23808 KB | Ok |
19 | Correct | 81 ms | 23700 KB | Ok |
20 | Correct | 26 ms | 23800 KB | Ok |
21 | Correct | 40 ms | 23736 KB | Ok |
22 | Correct | 13 ms | 23748 KB | Ok |
23 | Correct | 14 ms | 23708 KB | Ok |
24 | Correct | 17 ms | 23940 KB | Ok |
25 | Correct | 42 ms | 23956 KB | Ok |
26 | Correct | 21 ms | 24048 KB | Ok |
27 | Correct | 15 ms | 24012 KB | Ok |
28 | Correct | 16 ms | 24036 KB | Ok |
29 | Correct | 16 ms | 24024 KB | Ok |
30 | Correct | 18 ms | 23960 KB | Ok |
31 | Correct | 23 ms | 24088 KB | Ok |
32 | Correct | 21 ms | 23932 KB | Ok |
33 | Correct | 17 ms | 24068 KB | Ok |
34 | Correct | 28 ms | 24288 KB | Ok |
35 | Correct | 23 ms | 24360 KB | Ok |
36 | Correct | 22 ms | 24316 KB | Ok |
37 | Correct | 20 ms | 24396 KB | Ok |
38 | Correct | 23 ms | 24388 KB | Ok |
39 | Correct | 23 ms | 24304 KB | Ok |
40 | Correct | 23 ms | 24388 KB | Ok |
41 | Correct | 90 ms | 24388 KB | Ok |
42 | Correct | 24 ms | 24316 KB | Ok |
43 | Correct | 21 ms | 24396 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23756 KB | Ok |
2 | Correct | 15 ms | 23740 KB | Ok |
3 | Correct | 14 ms | 23784 KB | Ok |
4 | Correct | 22 ms | 23752 KB | Ok |
5 | Correct | 15 ms | 23808 KB | Ok |
6 | Correct | 14 ms | 23756 KB | Ok |
7 | Correct | 15 ms | 23800 KB | Ok |
8 | Correct | 14 ms | 23784 KB | Ok |
9 | Correct | 16 ms | 23756 KB | Ok |
10 | Correct | 15 ms | 23792 KB | Ok |
11 | Correct | 14 ms | 23756 KB | Ok |
12 | Correct | 14 ms | 23796 KB | Ok |
13 | Correct | 16 ms | 23820 KB | Ok |
14 | Correct | 32 ms | 23776 KB | Ok |
15 | Correct | 14 ms | 23776 KB | Ok |
16 | Correct | 15 ms | 23756 KB | Ok |
17 | Correct | 14 ms | 23756 KB | Ok |
18 | Correct | 17 ms | 24012 KB | Ok |
19 | Correct | 36 ms | 25216 KB | Ok |
20 | Correct | 28 ms | 24400 KB | Ok |
21 | Correct | 43 ms | 25412 KB | Ok |
22 | Correct | 27 ms | 24608 KB | Ok |
23 | Correct | 15 ms | 23736 KB | Ok |
24 | Correct | 13 ms | 23820 KB | Ok |
25 | Correct | 13 ms | 23756 KB | Ok |
26 | Correct | 16 ms | 23756 KB | Ok |
27 | Correct | 13 ms | 23776 KB | Ok |
28 | Correct | 16 ms | 23808 KB | Ok |
29 | Correct | 81 ms | 23700 KB | Ok |
30 | Correct | 26 ms | 23800 KB | Ok |
31 | Correct | 40 ms | 23736 KB | Ok |
32 | Correct | 13 ms | 23748 KB | Ok |
33 | Correct | 14 ms | 23708 KB | Ok |
34 | Correct | 17 ms | 23940 KB | Ok |
35 | Correct | 42 ms | 23956 KB | Ok |
36 | Correct | 21 ms | 24048 KB | Ok |
37 | Correct | 15 ms | 24012 KB | Ok |
38 | Correct | 16 ms | 24036 KB | Ok |
39 | Correct | 16 ms | 24024 KB | Ok |
40 | Correct | 18 ms | 23960 KB | Ok |
41 | Correct | 23 ms | 24088 KB | Ok |
42 | Correct | 21 ms | 23932 KB | Ok |
43 | Correct | 17 ms | 24068 KB | Ok |
44 | Correct | 28 ms | 24288 KB | Ok |
45 | Correct | 23 ms | 24360 KB | Ok |
46 | Correct | 22 ms | 24316 KB | Ok |
47 | Correct | 20 ms | 24396 KB | Ok |
48 | Correct | 23 ms | 24388 KB | Ok |
49 | Correct | 23 ms | 24304 KB | Ok |
50 | Correct | 23 ms | 24388 KB | Ok |
51 | Correct | 90 ms | 24388 KB | Ok |
52 | Correct | 24 ms | 24316 KB | Ok |
53 | Correct | 21 ms | 24396 KB | Ok |
54 | Correct | 174 ms | 31624 KB | Ok |
55 | Correct | 192 ms | 32080 KB | Ok |
56 | Correct | 179 ms | 32180 KB | Ok |
57 | Correct | 153 ms | 30852 KB | Ok |
58 | Correct | 185 ms | 31916 KB | Ok |
59 | Correct | 239 ms | 31412 KB | Ok |
60 | Correct | 188 ms | 30848 KB | Ok |
61 | Correct | 150 ms | 31296 KB | Ok |
62 | Correct | 240 ms | 32352 KB | Ok |
63 | Correct | 178 ms | 31140 KB | Ok |
64 | Correct | 231 ms | 31968 KB | Ok |
65 | Correct | 212 ms | 31920 KB | Ok |
66 | Correct | 184 ms | 31484 KB | Ok |
67 | Correct | 144 ms | 31172 KB | Ok |
68 | Correct | 180 ms | 31652 KB | Ok |
69 | Correct | 1080 ms | 40840 KB | Ok |
70 | Correct | 1002 ms | 41288 KB | Ok |
71 | Correct | 944 ms | 40844 KB | Ok |
72 | Correct | 866 ms | 40792 KB | Ok |
73 | Correct | 1057 ms | 41076 KB | Ok |
74 | Correct | 979 ms | 40740 KB | Ok |
75 | Correct | 883 ms | 40712 KB | Ok |
76 | Correct | 1012 ms | 41008 KB | Ok |
77 | Correct | 925 ms | 40748 KB | Ok |
78 | Correct | 1190 ms | 40848 KB | Ok |
79 | Correct | 873 ms | 41208 KB | Ok |
80 | Correct | 909 ms | 40952 KB | Ok |
81 | Correct | 927 ms | 41196 KB | Ok |
82 | Correct | 997 ms | 40880 KB | Ok |
83 | Correct | 818 ms | 40928 KB | Ok |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23756 KB | Ok |
2 | Correct | 15 ms | 23740 KB | Ok |
3 | Correct | 14 ms | 23784 KB | Ok |
4 | Correct | 22 ms | 23752 KB | Ok |
5 | Correct | 15 ms | 23808 KB | Ok |
6 | Correct | 14 ms | 23756 KB | Ok |
7 | Correct | 15 ms | 23800 KB | Ok |
8 | Correct | 14 ms | 23784 KB | Ok |
9 | Correct | 16 ms | 23756 KB | Ok |
10 | Correct | 15 ms | 23792 KB | Ok |
11 | Correct | 14 ms | 23756 KB | Ok |
12 | Correct | 14 ms | 23796 KB | Ok |
13 | Correct | 16 ms | 23820 KB | Ok |
14 | Correct | 32 ms | 23776 KB | Ok |
15 | Correct | 14 ms | 23776 KB | Ok |
16 | Correct | 15 ms | 23756 KB | Ok |
17 | Correct | 14 ms | 23756 KB | Ok |
18 | Correct | 17 ms | 24012 KB | Ok |
19 | Correct | 36 ms | 25216 KB | Ok |
20 | Correct | 28 ms | 24400 KB | Ok |
21 | Correct | 43 ms | 25412 KB | Ok |
22 | Correct | 27 ms | 24608 KB | Ok |
23 | Correct | 15 ms | 23736 KB | Ok |
24 | Correct | 13 ms | 23820 KB | Ok |
25 | Correct | 13 ms | 23756 KB | Ok |
26 | Correct | 16 ms | 23756 KB | Ok |
27 | Correct | 13 ms | 23776 KB | Ok |
28 | Correct | 16 ms | 23808 KB | Ok |
29 | Correct | 81 ms | 23700 KB | Ok |
30 | Correct | 26 ms | 23800 KB | Ok |
31 | Correct | 40 ms | 23736 KB | Ok |
32 | Correct | 13 ms | 23748 KB | Ok |
33 | Correct | 14 ms | 23708 KB | Ok |
34 | Correct | 16 ms | 23812 KB | Ok |
35 | Correct | 15 ms | 23756 KB | Ok |
36 | Correct | 16 ms | 23812 KB | Ok |
37 | Correct | 17 ms | 23824 KB | Ok |
38 | Correct | 15 ms | 23808 KB | Ok |
39 | Correct | 473 ms | 44692 KB | Ok |
40 | Correct | 297 ms | 47072 KB | Ok |
41 | Correct | 755 ms | 50212 KB | Ok |
42 | Correct | 575 ms | 48464 KB | Ok |
43 | Correct | 288 ms | 38164 KB | Ok |
44 | Correct | 571 ms | 50160 KB | Ok |
45 | Correct | 17 ms | 23940 KB | Ok |
46 | Correct | 42 ms | 23956 KB | Ok |
47 | Correct | 21 ms | 24048 KB | Ok |
48 | Correct | 15 ms | 24012 KB | Ok |
49 | Correct | 16 ms | 24036 KB | Ok |
50 | Correct | 16 ms | 24024 KB | Ok |
51 | Correct | 18 ms | 23960 KB | Ok |
52 | Correct | 23 ms | 24088 KB | Ok |
53 | Correct | 21 ms | 23932 KB | Ok |
54 | Correct | 17 ms | 24068 KB | Ok |
55 | Correct | 28 ms | 24288 KB | Ok |
56 | Correct | 23 ms | 24360 KB | Ok |
57 | Correct | 22 ms | 24316 KB | Ok |
58 | Correct | 20 ms | 24396 KB | Ok |
59 | Correct | 23 ms | 24388 KB | Ok |
60 | Correct | 23 ms | 24304 KB | Ok |
61 | Correct | 23 ms | 24388 KB | Ok |
62 | Correct | 90 ms | 24388 KB | Ok |
63 | Correct | 24 ms | 24316 KB | Ok |
64 | Correct | 21 ms | 24396 KB | Ok |
65 | Correct | 174 ms | 31624 KB | Ok |
66 | Correct | 192 ms | 32080 KB | Ok |
67 | Correct | 179 ms | 32180 KB | Ok |
68 | Correct | 153 ms | 30852 KB | Ok |
69 | Correct | 185 ms | 31916 KB | Ok |
70 | Correct | 239 ms | 31412 KB | Ok |
71 | Correct | 188 ms | 30848 KB | Ok |
72 | Correct | 150 ms | 31296 KB | Ok |
73 | Correct | 240 ms | 32352 KB | Ok |
74 | Correct | 178 ms | 31140 KB | Ok |
75 | Correct | 231 ms | 31968 KB | Ok |
76 | Correct | 212 ms | 31920 KB | Ok |
77 | Correct | 184 ms | 31484 KB | Ok |
78 | Correct | 144 ms | 31172 KB | Ok |
79 | Correct | 180 ms | 31652 KB | Ok |
80 | Correct | 1080 ms | 40840 KB | Ok |
81 | Correct | 1002 ms | 41288 KB | Ok |
82 | Correct | 944 ms | 40844 KB | Ok |
83 | Correct | 866 ms | 40792 KB | Ok |
84 | Correct | 1057 ms | 41076 KB | Ok |
85 | Correct | 979 ms | 40740 KB | Ok |
86 | Correct | 883 ms | 40712 KB | Ok |
87 | Correct | 1012 ms | 41008 KB | Ok |
88 | Correct | 925 ms | 40748 KB | Ok |
89 | Correct | 1190 ms | 40848 KB | Ok |
90 | Correct | 873 ms | 41208 KB | Ok |
91 | Correct | 909 ms | 40952 KB | Ok |
92 | Correct | 927 ms | 41196 KB | Ok |
93 | Correct | 997 ms | 40880 KB | Ok |
94 | Correct | 818 ms | 40928 KB | Ok |
95 | Correct | 520 ms | 44400 KB | Ok |
96 | Correct | 792 ms | 55188 KB | Ok |
97 | Correct | 707 ms | 49300 KB | Ok |
98 | Correct | 485 ms | 48436 KB | Ok |
99 | Correct | 572 ms | 48216 KB | Ok |
100 | Correct | 650 ms | 48336 KB | Ok |
101 | Correct | 656 ms | 51424 KB | Ok |
102 | Correct | 679 ms | 49744 KB | Ok |
103 | Correct | 652 ms | 51088 KB | Ok |
104 | Correct | 787 ms | 52760 KB | Ok |
105 | Correct | 783 ms | 55980 KB | Ok |
106 | Correct | 630 ms | 52960 KB | Ok |
107 | Correct | 739 ms | 52456 KB | Ok |
108 | Correct | 804 ms | 54620 KB | Ok |
109 | Correct | 625 ms | 54620 KB | Ok |
110 | Execution timed out | 2092 ms | 66068 KB | Time limit exceeded |
111 | Halted | 0 ms | 0 KB | - |