# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
497795 | 2021-12-23T20:15:59 Z | Ziel | Nice sequence (IZhO18_sequence) | C++17 | 1181 ms | 80092 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 = 4e5 + 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; } }*/ int res = n + m - gcd(n, m) - 1; 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; if (sz(g[i])) 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 5 ms | 9676 KB | Ok |
4 | Correct | 5 ms | 9636 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 5 ms | 9736 KB | Ok |
7 | Correct | 4 ms | 9676 KB | Ok |
8 | Correct | 5 ms | 9676 KB | Ok |
9 | Correct | 4 ms | 9676 KB | Ok |
10 | Correct | 4 ms | 9676 KB | Ok |
11 | Correct | 5 ms | 9676 KB | Ok |
12 | Correct | 5 ms | 9676 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9676 KB | Ok |
2 | Correct | 5 ms | 9676 KB | Ok |
3 | Correct | 5 ms | 9724 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 6 ms | 9932 KB | Ok |
7 | Correct | 13 ms | 10828 KB | Ok |
8 | Correct | 8 ms | 10188 KB | Ok |
9 | Correct | 14 ms | 11084 KB | Ok |
10 | Correct | 9 ms | 10444 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9676 KB | Ok |
2 | Correct | 5 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 5 ms | 9676 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 5 ms | 9636 KB | Ok |
7 | Correct | 5 ms | 9700 KB | Ok |
8 | Correct | 5 ms | 9676 KB | Ok |
9 | Correct | 5 ms | 9676 KB | Ok |
10 | Correct | 5 ms | 9664 KB | Ok |
11 | Correct | 5 ms | 9676 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9676 KB | Ok |
2 | Correct | 5 ms | 9676 KB | Ok |
3 | Correct | 5 ms | 9676 KB | Ok |
4 | Correct | 5 ms | 9628 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 84 ms | 30612 KB | Ok |
7 | Correct | 75 ms | 30564 KB | Ok |
8 | Correct | 148 ms | 34968 KB | Ok |
9 | Correct | 109 ms | 30376 KB | Ok |
10 | Correct | 65 ms | 24148 KB | Ok |
11 | Correct | 102 ms | 36004 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 5 ms | 9676 KB | Ok |
4 | Correct | 5 ms | 9636 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 5 ms | 9736 KB | Ok |
7 | Correct | 4 ms | 9676 KB | Ok |
8 | Correct | 5 ms | 9676 KB | Ok |
9 | Correct | 4 ms | 9676 KB | Ok |
10 | Correct | 4 ms | 9676 KB | Ok |
11 | Correct | 5 ms | 9676 KB | Ok |
12 | Correct | 5 ms | 9676 KB | Ok |
13 | Correct | 5 ms | 9676 KB | Ok |
14 | Correct | 5 ms | 9676 KB | Ok |
15 | Correct | 6 ms | 9676 KB | Ok |
16 | Correct | 5 ms | 9676 KB | Ok |
17 | Correct | 5 ms | 9676 KB | Ok |
18 | Correct | 5 ms | 9636 KB | Ok |
19 | Correct | 5 ms | 9700 KB | Ok |
20 | Correct | 5 ms | 9676 KB | Ok |
21 | Correct | 5 ms | 9676 KB | Ok |
22 | Correct | 5 ms | 9664 KB | Ok |
23 | Correct | 5 ms | 9676 KB | Ok |
24 | Correct | 6 ms | 9932 KB | Ok |
25 | Correct | 7 ms | 9916 KB | Ok |
26 | Correct | 6 ms | 9932 KB | Ok |
27 | Correct | 6 ms | 9932 KB | Ok |
28 | Correct | 6 ms | 9932 KB | Ok |
29 | Correct | 6 ms | 9804 KB | Ok |
30 | Correct | 6 ms | 9804 KB | Ok |
31 | Correct | 7 ms | 9932 KB | Ok |
32 | Correct | 6 ms | 9932 KB | Ok |
33 | Correct | 6 ms | 9932 KB | Ok |
34 | Correct | 8 ms | 10188 KB | Ok |
35 | Correct | 9 ms | 10236 KB | Ok |
36 | Correct | 8 ms | 10276 KB | Ok |
37 | Correct | 7 ms | 10188 KB | Ok |
38 | Correct | 8 ms | 10188 KB | Ok |
39 | Correct | 8 ms | 10124 KB | Ok |
40 | Correct | 8 ms | 10188 KB | Ok |
41 | Correct | 9 ms | 10188 KB | Ok |
42 | Correct | 8 ms | 10316 KB | Ok |
43 | Correct | 8 ms | 10188 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 5 ms | 9676 KB | Ok |
4 | Correct | 5 ms | 9636 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 5 ms | 9736 KB | Ok |
7 | Correct | 4 ms | 9676 KB | Ok |
8 | Correct | 5 ms | 9676 KB | Ok |
9 | Correct | 4 ms | 9676 KB | Ok |
10 | Correct | 4 ms | 9676 KB | Ok |
11 | Correct | 5 ms | 9676 KB | Ok |
12 | Correct | 5 ms | 9676 KB | Ok |
13 | Correct | 4 ms | 9676 KB | Ok |
14 | Correct | 5 ms | 9676 KB | Ok |
15 | Correct | 5 ms | 9724 KB | Ok |
16 | Correct | 6 ms | 9676 KB | Ok |
17 | Correct | 5 ms | 9676 KB | Ok |
18 | Correct | 6 ms | 9932 KB | Ok |
19 | Correct | 13 ms | 10828 KB | Ok |
20 | Correct | 8 ms | 10188 KB | Ok |
21 | Correct | 14 ms | 11084 KB | Ok |
22 | Correct | 9 ms | 10444 KB | Ok |
23 | Correct | 5 ms | 9676 KB | Ok |
24 | Correct | 5 ms | 9676 KB | Ok |
25 | Correct | 6 ms | 9676 KB | Ok |
26 | Correct | 5 ms | 9676 KB | Ok |
27 | Correct | 5 ms | 9676 KB | Ok |
28 | Correct | 5 ms | 9636 KB | Ok |
29 | Correct | 5 ms | 9700 KB | Ok |
30 | Correct | 5 ms | 9676 KB | Ok |
31 | Correct | 5 ms | 9676 KB | Ok |
32 | Correct | 5 ms | 9664 KB | Ok |
33 | Correct | 5 ms | 9676 KB | Ok |
34 | Correct | 6 ms | 9932 KB | Ok |
35 | Correct | 7 ms | 9916 KB | Ok |
36 | Correct | 6 ms | 9932 KB | Ok |
37 | Correct | 6 ms | 9932 KB | Ok |
38 | Correct | 6 ms | 9932 KB | Ok |
39 | Correct | 6 ms | 9804 KB | Ok |
40 | Correct | 6 ms | 9804 KB | Ok |
41 | Correct | 7 ms | 9932 KB | Ok |
42 | Correct | 6 ms | 9932 KB | Ok |
43 | Correct | 6 ms | 9932 KB | Ok |
44 | Correct | 8 ms | 10188 KB | Ok |
45 | Correct | 9 ms | 10236 KB | Ok |
46 | Correct | 8 ms | 10276 KB | Ok |
47 | Correct | 7 ms | 10188 KB | Ok |
48 | Correct | 8 ms | 10188 KB | Ok |
49 | Correct | 8 ms | 10124 KB | Ok |
50 | Correct | 8 ms | 10188 KB | Ok |
51 | Correct | 9 ms | 10188 KB | Ok |
52 | Correct | 8 ms | 10316 KB | Ok |
53 | Correct | 8 ms | 10188 KB | Ok |
54 | Correct | 58 ms | 17504 KB | Ok |
55 | Correct | 68 ms | 18044 KB | Ok |
56 | Correct | 70 ms | 18036 KB | Ok |
57 | Correct | 51 ms | 16672 KB | Ok |
58 | Correct | 62 ms | 17832 KB | Ok |
59 | Correct | 59 ms | 17360 KB | Ok |
60 | Correct | 55 ms | 16760 KB | Ok |
61 | Correct | 56 ms | 17144 KB | Ok |
62 | Correct | 71 ms | 18192 KB | Ok |
63 | Correct | 55 ms | 17028 KB | Ok |
64 | Correct | 67 ms | 17844 KB | Ok |
65 | Correct | 63 ms | 17744 KB | Ok |
66 | Correct | 57 ms | 17380 KB | Ok |
67 | Correct | 56 ms | 17032 KB | Ok |
68 | Correct | 61 ms | 17604 KB | Ok |
69 | Correct | 155 ms | 26552 KB | Ok |
70 | Correct | 183 ms | 26548 KB | Ok |
71 | Correct | 155 ms | 24372 KB | Ok |
72 | Correct | 150 ms | 26576 KB | Ok |
73 | Correct | 153 ms | 24628 KB | Ok |
74 | Correct | 160 ms | 25552 KB | Ok |
75 | Correct | 145 ms | 26272 KB | Ok |
76 | Correct | 162 ms | 26468 KB | Ok |
77 | Correct | 146 ms | 25256 KB | Ok |
78 | Correct | 172 ms | 26680 KB | Ok |
79 | Correct | 163 ms | 25732 KB | Ok |
80 | Correct | 155 ms | 24548 KB | Ok |
81 | Correct | 160 ms | 26544 KB | Ok |
82 | Correct | 160 ms | 25628 KB | Ok |
83 | Correct | 156 ms | 26652 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 5 ms | 9676 KB | Ok |
4 | Correct | 5 ms | 9636 KB | Ok |
5 | Correct | 5 ms | 9676 KB | Ok |
6 | Correct | 5 ms | 9736 KB | Ok |
7 | Correct | 4 ms | 9676 KB | Ok |
8 | Correct | 5 ms | 9676 KB | Ok |
9 | Correct | 4 ms | 9676 KB | Ok |
10 | Correct | 4 ms | 9676 KB | Ok |
11 | Correct | 5 ms | 9676 KB | Ok |
12 | Correct | 5 ms | 9676 KB | Ok |
13 | Correct | 4 ms | 9676 KB | Ok |
14 | Correct | 5 ms | 9676 KB | Ok |
15 | Correct | 5 ms | 9724 KB | Ok |
16 | Correct | 6 ms | 9676 KB | Ok |
17 | Correct | 5 ms | 9676 KB | Ok |
18 | Correct | 6 ms | 9932 KB | Ok |
19 | Correct | 13 ms | 10828 KB | Ok |
20 | Correct | 8 ms | 10188 KB | Ok |
21 | Correct | 14 ms | 11084 KB | Ok |
22 | Correct | 9 ms | 10444 KB | Ok |
23 | Correct | 5 ms | 9676 KB | Ok |
24 | Correct | 5 ms | 9676 KB | Ok |
25 | Correct | 6 ms | 9676 KB | Ok |
26 | Correct | 5 ms | 9676 KB | Ok |
27 | Correct | 5 ms | 9676 KB | Ok |
28 | Correct | 5 ms | 9636 KB | Ok |
29 | Correct | 5 ms | 9700 KB | Ok |
30 | Correct | 5 ms | 9676 KB | Ok |
31 | Correct | 5 ms | 9676 KB | Ok |
32 | Correct | 5 ms | 9664 KB | Ok |
33 | Correct | 5 ms | 9676 KB | Ok |
34 | Correct | 5 ms | 9676 KB | Ok |
35 | Correct | 5 ms | 9676 KB | Ok |
36 | Correct | 5 ms | 9676 KB | Ok |
37 | Correct | 5 ms | 9628 KB | Ok |
38 | Correct | 5 ms | 9676 KB | Ok |
39 | Correct | 84 ms | 30612 KB | Ok |
40 | Correct | 75 ms | 30564 KB | Ok |
41 | Correct | 148 ms | 34968 KB | Ok |
42 | Correct | 109 ms | 30376 KB | Ok |
43 | Correct | 65 ms | 24148 KB | Ok |
44 | Correct | 102 ms | 36004 KB | Ok |
45 | Correct | 6 ms | 9932 KB | Ok |
46 | Correct | 7 ms | 9916 KB | Ok |
47 | Correct | 6 ms | 9932 KB | Ok |
48 | Correct | 6 ms | 9932 KB | Ok |
49 | Correct | 6 ms | 9932 KB | Ok |
50 | Correct | 6 ms | 9804 KB | Ok |
51 | Correct | 6 ms | 9804 KB | Ok |
52 | Correct | 7 ms | 9932 KB | Ok |
53 | Correct | 6 ms | 9932 KB | Ok |
54 | Correct | 6 ms | 9932 KB | Ok |
55 | Correct | 8 ms | 10188 KB | Ok |
56 | Correct | 9 ms | 10236 KB | Ok |
57 | Correct | 8 ms | 10276 KB | Ok |
58 | Correct | 7 ms | 10188 KB | Ok |
59 | Correct | 8 ms | 10188 KB | Ok |
60 | Correct | 8 ms | 10124 KB | Ok |
61 | Correct | 8 ms | 10188 KB | Ok |
62 | Correct | 9 ms | 10188 KB | Ok |
63 | Correct | 8 ms | 10316 KB | Ok |
64 | Correct | 8 ms | 10188 KB | Ok |
65 | Correct | 58 ms | 17504 KB | Ok |
66 | Correct | 68 ms | 18044 KB | Ok |
67 | Correct | 70 ms | 18036 KB | Ok |
68 | Correct | 51 ms | 16672 KB | Ok |
69 | Correct | 62 ms | 17832 KB | Ok |
70 | Correct | 59 ms | 17360 KB | Ok |
71 | Correct | 55 ms | 16760 KB | Ok |
72 | Correct | 56 ms | 17144 KB | Ok |
73 | Correct | 71 ms | 18192 KB | Ok |
74 | Correct | 55 ms | 17028 KB | Ok |
75 | Correct | 67 ms | 17844 KB | Ok |
76 | Correct | 63 ms | 17744 KB | Ok |
77 | Correct | 57 ms | 17380 KB | Ok |
78 | Correct | 56 ms | 17032 KB | Ok |
79 | Correct | 61 ms | 17604 KB | Ok |
80 | Correct | 155 ms | 26552 KB | Ok |
81 | Correct | 183 ms | 26548 KB | Ok |
82 | Correct | 155 ms | 24372 KB | Ok |
83 | Correct | 150 ms | 26576 KB | Ok |
84 | Correct | 153 ms | 24628 KB | Ok |
85 | Correct | 160 ms | 25552 KB | Ok |
86 | Correct | 145 ms | 26272 KB | Ok |
87 | Correct | 162 ms | 26468 KB | Ok |
88 | Correct | 146 ms | 25256 KB | Ok |
89 | Correct | 172 ms | 26680 KB | Ok |
90 | Correct | 163 ms | 25732 KB | Ok |
91 | Correct | 155 ms | 24548 KB | Ok |
92 | Correct | 160 ms | 26544 KB | Ok |
93 | Correct | 160 ms | 25628 KB | Ok |
94 | Correct | 156 ms | 26652 KB | Ok |
95 | Correct | 156 ms | 30224 KB | Ok |
96 | Correct | 227 ms | 41024 KB | Ok |
97 | Correct | 202 ms | 34800 KB | Ok |
98 | Correct | 156 ms | 34192 KB | Ok |
99 | Correct | 181 ms | 33832 KB | Ok |
100 | Correct | 187 ms | 34056 KB | Ok |
101 | Correct | 193 ms | 37360 KB | Ok |
102 | Correct | 195 ms | 35796 KB | Ok |
103 | Correct | 183 ms | 36784 KB | Ok |
104 | Correct | 215 ms | 38596 KB | Ok |
105 | Correct | 220 ms | 41608 KB | Ok |
106 | Correct | 176 ms | 38864 KB | Ok |
107 | Correct | 198 ms | 38320 KB | Ok |
108 | Correct | 230 ms | 40548 KB | Ok |
109 | Correct | 212 ms | 40396 KB | Ok |
110 | Correct | 984 ms | 79460 KB | Ok |
111 | Correct | 1159 ms | 80092 KB | Ok |
112 | Correct | 1130 ms | 73468 KB | Ok |
113 | Correct | 941 ms | 79136 KB | Ok |
114 | Correct | 1052 ms | 72208 KB | Ok |
115 | Correct | 1181 ms | 80076 KB | Ok |
116 | Correct | 1094 ms | 79144 KB | Ok |
117 | Correct | 1073 ms | 79896 KB | Ok |
118 | Correct | 1100 ms | 70956 KB | Ok |
119 | Correct | 1080 ms | 79096 KB | Ok |
120 | Correct | 1082 ms | 80084 KB | Ok |
121 | Correct | 1022 ms | 76888 KB | Ok |
122 | Correct | 994 ms | 79728 KB | Ok |
123 | Correct | 1145 ms | 76796 KB | Ok |
124 | Correct | 1027 ms | 72616 KB | Ok |
125 | Correct | 338 ms | 63624 KB | Ok |