# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
65822 | 2018-08-09T00:51:20 Z | kingpig9 | Nice sequence (IZhO18_sequence) | C++11 | 1671 ms | 35400 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4e5 + 10; #define debug(...) fprintf(stderr, __VA_ARGS__) #define all(v) (v).begin(), (v).end() #define fi first #define se second #define fillchar(a, s) memset((a), (s), sizeof(a)) int N, M; stack<int> stk; vector<int> topo; int indeg[MAXN]; bool moo (int g, bool isfinal = false) { if (isfinal) { topo.clear(); } //x -> x + M or x + N -> x for (int x = 0; x <= g; x++) { indeg[x] = 0; //adj[x].clear(); } for (int x = 0; x + M <= g; x++) { //adj[x].push_back(x + M); indeg[x + M]++; } for (int x = 0; x + N <= g; x++) { //adj[x + N].push_back(x); indeg[x]++; } for (int x = 0; x <= g; x++) { if (indeg[x] == 0) { stk.push(x); } } while (!stk.empty()) { int x = stk.top(); stk.pop(); if (isfinal) { topo.push_back(x); } if (x - N >= 0 && --indeg[x - N] == 0) { stk.push(x - N); } if (x + M <= g && --indeg[x + M] == 0) { stk.push(x + M); } } for (int x = 0; x <= g; x++) { if (indeg[x]) { return false; } } return true; } int ans[MAXN]; int go() { int lo = min(N, M) - 1, hi = N + M; while (hi - lo > 1) { int mid = (lo + hi) / 2; if (moo(mid)) { lo = mid; } else { hi = mid; } } assert(moo(lo, true)); int ind0 = find(all(topo), 0) - topo.begin(); for (int i = 0; i <= lo; i++) { ans[topo[i]] = i - ind0; } for (int i = lo; i >= 1; i--) { ans[i] -= ans[i - 1]; } return lo; } int main() { int nq; scanf("%d", &nq); for (int qi = 1; qi <= nq; qi++) { scanf("%d %d", &N, &M); int len = go(); printf("%d\n", len); for (int i = 1; i <= len; i++) { printf("%d ", ans[i]); } puts(""); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 472 KB | Ok |
3 | Correct | 3 ms | 472 KB | Ok |
4 | Correct | 3 ms | 636 KB | Ok |
5 | Correct | 3 ms | 636 KB | Ok |
6 | Correct | 2 ms | 636 KB | Ok |
7 | Correct | 3 ms | 636 KB | Ok |
8 | Correct | 2 ms | 636 KB | Ok |
9 | Correct | 3 ms | 636 KB | Ok |
10 | Correct | 2 ms | 636 KB | Ok |
11 | Correct | 2 ms | 636 KB | Ok |
12 | Correct | 3 ms | 636 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 636 KB | Ok |
2 | Correct | 2 ms | 644 KB | Ok |
3 | Correct | 4 ms | 644 KB | Ok |
4 | Correct | 3 ms | 652 KB | Ok |
5 | Correct | 3 ms | 656 KB | Ok |
6 | Correct | 8 ms | 672 KB | Ok |
7 | Correct | 26 ms | 1204 KB | Ok |
8 | Correct | 11 ms | 1204 KB | Ok |
9 | Correct | 26 ms | 1344 KB | Ok |
10 | Correct | 15 ms | 1344 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1344 KB | Ok |
2 | Correct | 3 ms | 1344 KB | Ok |
3 | Correct | 3 ms | 1344 KB | Ok |
4 | Correct | 3 ms | 1344 KB | Ok |
5 | Correct | 3 ms | 1344 KB | Ok |
6 | Correct | 3 ms | 1344 KB | Ok |
7 | Correct | 3 ms | 1344 KB | Ok |
8 | Correct | 4 ms | 1344 KB | Ok |
9 | Correct | 2 ms | 1344 KB | Ok |
10 | Correct | 3 ms | 1344 KB | Ok |
11 | Correct | 3 ms | 1344 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1344 KB | Ok |
2 | Correct | 2 ms | 1344 KB | Ok |
3 | Correct | 3 ms | 1344 KB | Ok |
4 | Correct | 2 ms | 1344 KB | Ok |
5 | Correct | 3 ms | 1344 KB | Ok |
6 | Correct | 246 ms | 7188 KB | Ok |
7 | Correct | 200 ms | 7188 KB | Ok |
8 | Correct | 388 ms | 9424 KB | Ok |
9 | Correct | 273 ms | 9424 KB | Ok |
10 | Correct | 155 ms | 9424 KB | Ok |
11 | Correct | 273 ms | 9424 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 472 KB | Ok |
3 | Correct | 3 ms | 472 KB | Ok |
4 | Correct | 3 ms | 636 KB | Ok |
5 | Correct | 3 ms | 636 KB | Ok |
6 | Correct | 2 ms | 636 KB | Ok |
7 | Correct | 3 ms | 636 KB | Ok |
8 | Correct | 2 ms | 636 KB | Ok |
9 | Correct | 3 ms | 636 KB | Ok |
10 | Correct | 2 ms | 636 KB | Ok |
11 | Correct | 2 ms | 636 KB | Ok |
12 | Correct | 3 ms | 636 KB | Ok |
13 | Correct | 2 ms | 1344 KB | Ok |
14 | Correct | 3 ms | 1344 KB | Ok |
15 | Correct | 3 ms | 1344 KB | Ok |
16 | Correct | 3 ms | 1344 KB | Ok |
17 | Correct | 3 ms | 1344 KB | Ok |
18 | Correct | 3 ms | 1344 KB | Ok |
19 | Correct | 3 ms | 1344 KB | Ok |
20 | Correct | 4 ms | 1344 KB | Ok |
21 | Correct | 2 ms | 1344 KB | Ok |
22 | Correct | 3 ms | 1344 KB | Ok |
23 | Correct | 3 ms | 1344 KB | Ok |
24 | Correct | 8 ms | 9424 KB | Ok |
25 | Correct | 7 ms | 9424 KB | Ok |
26 | Correct | 7 ms | 9424 KB | Ok |
27 | Correct | 6 ms | 9424 KB | Ok |
28 | Correct | 6 ms | 9424 KB | Ok |
29 | Correct | 6 ms | 9424 KB | Ok |
30 | Correct | 6 ms | 9424 KB | Ok |
31 | Correct | 6 ms | 9424 KB | Ok |
32 | Correct | 7 ms | 9424 KB | Ok |
33 | Correct | 6 ms | 9424 KB | Ok |
34 | Correct | 13 ms | 9424 KB | Ok |
35 | Correct | 12 ms | 9424 KB | Ok |
36 | Correct | 13 ms | 9424 KB | Ok |
37 | Correct | 13 ms | 9424 KB | Ok |
38 | Correct | 14 ms | 9424 KB | Ok |
39 | Correct | 11 ms | 9424 KB | Ok |
40 | Correct | 11 ms | 9424 KB | Ok |
41 | Correct | 11 ms | 9424 KB | Ok |
42 | Correct | 12 ms | 9424 KB | Ok |
43 | Correct | 14 ms | 9424 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 472 KB | Ok |
3 | Correct | 3 ms | 472 KB | Ok |
4 | Correct | 3 ms | 636 KB | Ok |
5 | Correct | 3 ms | 636 KB | Ok |
6 | Correct | 2 ms | 636 KB | Ok |
7 | Correct | 3 ms | 636 KB | Ok |
8 | Correct | 2 ms | 636 KB | Ok |
9 | Correct | 3 ms | 636 KB | Ok |
10 | Correct | 2 ms | 636 KB | Ok |
11 | Correct | 2 ms | 636 KB | Ok |
12 | Correct | 3 ms | 636 KB | Ok |
13 | Correct | 2 ms | 636 KB | Ok |
14 | Correct | 2 ms | 644 KB | Ok |
15 | Correct | 4 ms | 644 KB | Ok |
16 | Correct | 3 ms | 652 KB | Ok |
17 | Correct | 3 ms | 656 KB | Ok |
18 | Correct | 8 ms | 672 KB | Ok |
19 | Correct | 26 ms | 1204 KB | Ok |
20 | Correct | 11 ms | 1204 KB | Ok |
21 | Correct | 26 ms | 1344 KB | Ok |
22 | Correct | 15 ms | 1344 KB | Ok |
23 | Correct | 2 ms | 1344 KB | Ok |
24 | Correct | 3 ms | 1344 KB | Ok |
25 | Correct | 3 ms | 1344 KB | Ok |
26 | Correct | 3 ms | 1344 KB | Ok |
27 | Correct | 3 ms | 1344 KB | Ok |
28 | Correct | 3 ms | 1344 KB | Ok |
29 | Correct | 3 ms | 1344 KB | Ok |
30 | Correct | 4 ms | 1344 KB | Ok |
31 | Correct | 2 ms | 1344 KB | Ok |
32 | Correct | 3 ms | 1344 KB | Ok |
33 | Correct | 3 ms | 1344 KB | Ok |
34 | Correct | 8 ms | 9424 KB | Ok |
35 | Correct | 7 ms | 9424 KB | Ok |
36 | Correct | 7 ms | 9424 KB | Ok |
37 | Correct | 6 ms | 9424 KB | Ok |
38 | Correct | 6 ms | 9424 KB | Ok |
39 | Correct | 6 ms | 9424 KB | Ok |
40 | Correct | 6 ms | 9424 KB | Ok |
41 | Correct | 6 ms | 9424 KB | Ok |
42 | Correct | 7 ms | 9424 KB | Ok |
43 | Correct | 6 ms | 9424 KB | Ok |
44 | Correct | 13 ms | 9424 KB | Ok |
45 | Correct | 12 ms | 9424 KB | Ok |
46 | Correct | 13 ms | 9424 KB | Ok |
47 | Correct | 13 ms | 9424 KB | Ok |
48 | Correct | 14 ms | 9424 KB | Ok |
49 | Correct | 11 ms | 9424 KB | Ok |
50 | Correct | 11 ms | 9424 KB | Ok |
51 | Correct | 11 ms | 9424 KB | Ok |
52 | Correct | 12 ms | 9424 KB | Ok |
53 | Correct | 14 ms | 9424 KB | Ok |
54 | Correct | 191 ms | 9424 KB | Ok |
55 | Correct | 263 ms | 9424 KB | Ok |
56 | Correct | 237 ms | 9424 KB | Ok |
57 | Correct | 156 ms | 9424 KB | Ok |
58 | Correct | 180 ms | 9424 KB | Ok |
59 | Correct | 249 ms | 9424 KB | Ok |
60 | Correct | 159 ms | 9424 KB | Ok |
61 | Correct | 148 ms | 9424 KB | Ok |
62 | Correct | 219 ms | 9424 KB | Ok |
63 | Correct | 171 ms | 9424 KB | Ok |
64 | Correct | 264 ms | 9424 KB | Ok |
65 | Correct | 221 ms | 9424 KB | Ok |
66 | Correct | 193 ms | 9424 KB | Ok |
67 | Correct | 161 ms | 9424 KB | Ok |
68 | Correct | 193 ms | 9424 KB | Ok |
69 | Correct | 332 ms | 9424 KB | Ok |
70 | Correct | 383 ms | 9424 KB | Ok |
71 | Correct | 337 ms | 9424 KB | Ok |
72 | Correct | 331 ms | 9424 KB | Ok |
73 | Correct | 338 ms | 9424 KB | Ok |
74 | Correct | 412 ms | 9424 KB | Ok |
75 | Correct | 407 ms | 9424 KB | Ok |
76 | Correct | 338 ms | 9424 KB | Ok |
77 | Correct | 373 ms | 9424 KB | Ok |
78 | Correct | 289 ms | 9424 KB | Ok |
79 | Correct | 288 ms | 9424 KB | Ok |
80 | Correct | 317 ms | 9424 KB | Ok |
81 | Correct | 318 ms | 9424 KB | Ok |
82 | Correct | 312 ms | 9424 KB | Ok |
83 | Correct | 369 ms | 9424 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Ok |
2 | Correct | 2 ms | 472 KB | Ok |
3 | Correct | 3 ms | 472 KB | Ok |
4 | Correct | 3 ms | 636 KB | Ok |
5 | Correct | 3 ms | 636 KB | Ok |
6 | Correct | 2 ms | 636 KB | Ok |
7 | Correct | 3 ms | 636 KB | Ok |
8 | Correct | 2 ms | 636 KB | Ok |
9 | Correct | 3 ms | 636 KB | Ok |
10 | Correct | 2 ms | 636 KB | Ok |
11 | Correct | 2 ms | 636 KB | Ok |
12 | Correct | 3 ms | 636 KB | Ok |
13 | Correct | 2 ms | 636 KB | Ok |
14 | Correct | 2 ms | 644 KB | Ok |
15 | Correct | 4 ms | 644 KB | Ok |
16 | Correct | 3 ms | 652 KB | Ok |
17 | Correct | 3 ms | 656 KB | Ok |
18 | Correct | 8 ms | 672 KB | Ok |
19 | Correct | 26 ms | 1204 KB | Ok |
20 | Correct | 11 ms | 1204 KB | Ok |
21 | Correct | 26 ms | 1344 KB | Ok |
22 | Correct | 15 ms | 1344 KB | Ok |
23 | Correct | 2 ms | 1344 KB | Ok |
24 | Correct | 3 ms | 1344 KB | Ok |
25 | Correct | 3 ms | 1344 KB | Ok |
26 | Correct | 3 ms | 1344 KB | Ok |
27 | Correct | 3 ms | 1344 KB | Ok |
28 | Correct | 3 ms | 1344 KB | Ok |
29 | Correct | 3 ms | 1344 KB | Ok |
30 | Correct | 4 ms | 1344 KB | Ok |
31 | Correct | 2 ms | 1344 KB | Ok |
32 | Correct | 3 ms | 1344 KB | Ok |
33 | Correct | 3 ms | 1344 KB | Ok |
34 | Correct | 4 ms | 1344 KB | Ok |
35 | Correct | 2 ms | 1344 KB | Ok |
36 | Correct | 3 ms | 1344 KB | Ok |
37 | Correct | 2 ms | 1344 KB | Ok |
38 | Correct | 3 ms | 1344 KB | Ok |
39 | Correct | 246 ms | 7188 KB | Ok |
40 | Correct | 200 ms | 7188 KB | Ok |
41 | Correct | 388 ms | 9424 KB | Ok |
42 | Correct | 273 ms | 9424 KB | Ok |
43 | Correct | 155 ms | 9424 KB | Ok |
44 | Correct | 273 ms | 9424 KB | Ok |
45 | Correct | 8 ms | 9424 KB | Ok |
46 | Correct | 7 ms | 9424 KB | Ok |
47 | Correct | 7 ms | 9424 KB | Ok |
48 | Correct | 6 ms | 9424 KB | Ok |
49 | Correct | 6 ms | 9424 KB | Ok |
50 | Correct | 6 ms | 9424 KB | Ok |
51 | Correct | 6 ms | 9424 KB | Ok |
52 | Correct | 6 ms | 9424 KB | Ok |
53 | Correct | 7 ms | 9424 KB | Ok |
54 | Correct | 6 ms | 9424 KB | Ok |
55 | Correct | 13 ms | 9424 KB | Ok |
56 | Correct | 12 ms | 9424 KB | Ok |
57 | Correct | 13 ms | 9424 KB | Ok |
58 | Correct | 13 ms | 9424 KB | Ok |
59 | Correct | 14 ms | 9424 KB | Ok |
60 | Correct | 11 ms | 9424 KB | Ok |
61 | Correct | 11 ms | 9424 KB | Ok |
62 | Correct | 11 ms | 9424 KB | Ok |
63 | Correct | 12 ms | 9424 KB | Ok |
64 | Correct | 14 ms | 9424 KB | Ok |
65 | Correct | 191 ms | 9424 KB | Ok |
66 | Correct | 263 ms | 9424 KB | Ok |
67 | Correct | 237 ms | 9424 KB | Ok |
68 | Correct | 156 ms | 9424 KB | Ok |
69 | Correct | 180 ms | 9424 KB | Ok |
70 | Correct | 249 ms | 9424 KB | Ok |
71 | Correct | 159 ms | 9424 KB | Ok |
72 | Correct | 148 ms | 9424 KB | Ok |
73 | Correct | 219 ms | 9424 KB | Ok |
74 | Correct | 171 ms | 9424 KB | Ok |
75 | Correct | 264 ms | 9424 KB | Ok |
76 | Correct | 221 ms | 9424 KB | Ok |
77 | Correct | 193 ms | 9424 KB | Ok |
78 | Correct | 161 ms | 9424 KB | Ok |
79 | Correct | 193 ms | 9424 KB | Ok |
80 | Correct | 332 ms | 9424 KB | Ok |
81 | Correct | 383 ms | 9424 KB | Ok |
82 | Correct | 337 ms | 9424 KB | Ok |
83 | Correct | 331 ms | 9424 KB | Ok |
84 | Correct | 338 ms | 9424 KB | Ok |
85 | Correct | 412 ms | 9424 KB | Ok |
86 | Correct | 407 ms | 9424 KB | Ok |
87 | Correct | 338 ms | 9424 KB | Ok |
88 | Correct | 373 ms | 9424 KB | Ok |
89 | Correct | 289 ms | 9424 KB | Ok |
90 | Correct | 288 ms | 9424 KB | Ok |
91 | Correct | 317 ms | 9424 KB | Ok |
92 | Correct | 318 ms | 9424 KB | Ok |
93 | Correct | 312 ms | 9424 KB | Ok |
94 | Correct | 369 ms | 9424 KB | Ok |
95 | Correct | 419 ms | 10752 KB | Ok |
96 | Correct | 776 ms | 14872 KB | Ok |
97 | Correct | 733 ms | 14872 KB | Ok |
98 | Correct | 446 ms | 14872 KB | Ok |
99 | Correct | 655 ms | 14872 KB | Ok |
100 | Correct | 655 ms | 14872 KB | Ok |
101 | Correct | 739 ms | 14872 KB | Ok |
102 | Correct | 721 ms | 14872 KB | Ok |
103 | Correct | 618 ms | 14872 KB | Ok |
104 | Correct | 724 ms | 14984 KB | Ok |
105 | Correct | 765 ms | 14984 KB | Ok |
106 | Correct | 612 ms | 14984 KB | Ok |
107 | Correct | 717 ms | 14984 KB | Ok |
108 | Correct | 757 ms | 14984 KB | Ok |
109 | Correct | 639 ms | 14984 KB | Ok |
110 | Correct | 1386 ms | 33256 KB | Ok |
111 | Correct | 1498 ms | 33420 KB | Ok |
112 | Correct | 1402 ms | 35400 KB | Ok |
113 | Correct | 1639 ms | 35400 KB | Ok |
114 | Correct | 1671 ms | 35400 KB | Ok |
115 | Correct | 1661 ms | 35400 KB | Ok |
116 | Correct | 1624 ms | 35400 KB | Ok |
117 | Correct | 1543 ms | 35400 KB | Ok |
118 | Correct | 1517 ms | 35400 KB | Ok |
119 | Correct | 1562 ms | 35400 KB | Ok |
120 | Correct | 1497 ms | 35400 KB | Ok |
121 | Correct | 1553 ms | 35400 KB | Ok |
122 | Correct | 1527 ms | 35400 KB | Ok |
123 | Correct | 1539 ms | 35400 KB | Ok |
124 | Correct | 1449 ms | 35400 KB | Ok |
125 | Correct | 1181 ms | 35400 KB | Ok |