# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
46528 | 2018-04-21T09:54:36 Z | Bruteforceman | Nice sequence (IZhO18_sequence) | C++11 | 1751 ms | 56168 KB |
#include "bits/stdc++.h" using namespace std; int N, M; vector <int> g[400010]; int solution[400010], pref[400010]; int deg[400010]; int v[400010]; void solve(int size) { for(int i = 0; i <= size; i++) { g[i].clear(); deg[i] = 0; } for(int i = N; i <= size; i++) { g[i].push_back(i - N); ++deg[i - N]; } for(int i = 0; i <= size - M; i++) { g[i].push_back(i + M); ++deg[i + M]; } queue <int> Q; for(int i = 0; i <= size; i++) { if(deg[i] == 0) { Q.push(i); } } int cnt = 0; while(!Q.empty()) { int x = Q.front(); Q.pop(); v[cnt++] = x; for(auto i : g[x]) { --deg[i]; if(deg[i] == 0) { Q.push(i); } } } if(cnt == size + 1) { for(int i = 0; i < cnt; i++) { if(v[i] == 0) { int cur = 0; for(int j = i-1; j >= 0; j--) { pref[v[j]] = --cur; } cur = 0; for(int j = i+1; j < cnt; j++) { pref[v[j]] = ++cur; } pref[v[i]] = 0; break; } } for(int i = 1; i <= size; i++) { solution[i] = pref[i] - pref[i - 1]; } } else { assert(false); } } int main(int argc, char const *argv[]) { int test; scanf("%d", &test); for(int cs = 1; cs <= test; cs++) { scanf("%d %d", &N, &M); int ans = 0; if(N == M) { ans = N-1; } else if (N > M) { int diff = N % M; for(int i = 0; i < M; i++) { long long val = 1LL * i * diff; val %= M; ans = max(ans, (int) val); } ans += N - 1; } else { int diff = M % N; for(int i = 0; i < N; i++) { long long val = 1LL * i * diff; val %= N; ans = max(ans, (int) val); } ans += M - 1; } solve(ans); printf("%d\n", ans); for(int i = 1; i <= ans; i++) { printf("%d ", solution[i]); } printf("\n"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Ok |
2 | Correct | 9 ms | 9832 KB | Ok |
3 | Correct | 11 ms | 9832 KB | Ok |
4 | Correct | 11 ms | 9832 KB | Ok |
5 | Correct | 10 ms | 9960 KB | Ok |
6 | Correct | 9 ms | 9960 KB | Ok |
7 | Correct | 9 ms | 9960 KB | Ok |
8 | Correct | 9 ms | 10032 KB | Ok |
9 | Correct | 9 ms | 10032 KB | Ok |
10 | Correct | 11 ms | 10032 KB | Ok |
11 | Correct | 9 ms | 10032 KB | Ok |
12 | Correct | 9 ms | 10068 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 10068 KB | Ok |
2 | Correct | 9 ms | 10068 KB | Ok |
3 | Correct | 9 ms | 10084 KB | Ok |
4 | Correct | 11 ms | 10084 KB | Ok |
5 | Correct | 9 ms | 10084 KB | Ok |
6 | Correct | 11 ms | 10088 KB | Ok |
7 | Correct | 20 ms | 10648 KB | Ok |
8 | Correct | 14 ms | 10648 KB | Ok |
9 | Correct | 24 ms | 10868 KB | Ok |
10 | Correct | 16 ms | 10868 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 10868 KB | Ok |
2 | Correct | 12 ms | 10868 KB | Ok |
3 | Correct | 9 ms | 10868 KB | Ok |
4 | Correct | 10 ms | 10868 KB | Ok |
5 | Correct | 9 ms | 10868 KB | Ok |
6 | Correct | 9 ms | 10868 KB | Ok |
7 | Correct | 9 ms | 10868 KB | Ok |
8 | Correct | 9 ms | 10868 KB | Ok |
9 | Correct | 9 ms | 10868 KB | Ok |
10 | Correct | 10 ms | 10868 KB | Ok |
11 | Correct | 9 ms | 10868 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 10868 KB | Ok |
2 | Correct | 9 ms | 10868 KB | Ok |
3 | Correct | 9 ms | 10868 KB | Ok |
4 | Correct | 9 ms | 10868 KB | Ok |
5 | Correct | 9 ms | 10868 KB | Ok |
6 | Correct | 113 ms | 20636 KB | Ok |
7 | Correct | 123 ms | 21276 KB | Ok |
8 | Correct | 191 ms | 23212 KB | Ok |
9 | Correct | 161 ms | 23212 KB | Ok |
10 | Correct | 90 ms | 23212 KB | Ok |
11 | Correct | 139 ms | 23212 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Ok |
2 | Correct | 9 ms | 9832 KB | Ok |
3 | Correct | 11 ms | 9832 KB | Ok |
4 | Correct | 11 ms | 9832 KB | Ok |
5 | Correct | 10 ms | 9960 KB | Ok |
6 | Correct | 9 ms | 9960 KB | Ok |
7 | Correct | 9 ms | 9960 KB | Ok |
8 | Correct | 9 ms | 10032 KB | Ok |
9 | Correct | 9 ms | 10032 KB | Ok |
10 | Correct | 11 ms | 10032 KB | Ok |
11 | Correct | 9 ms | 10032 KB | Ok |
12 | Correct | 9 ms | 10068 KB | Ok |
13 | Correct | 10 ms | 10868 KB | Ok |
14 | Correct | 12 ms | 10868 KB | Ok |
15 | Correct | 9 ms | 10868 KB | Ok |
16 | Correct | 10 ms | 10868 KB | Ok |
17 | Correct | 9 ms | 10868 KB | Ok |
18 | Correct | 9 ms | 10868 KB | Ok |
19 | Correct | 9 ms | 10868 KB | Ok |
20 | Correct | 9 ms | 10868 KB | Ok |
21 | Correct | 9 ms | 10868 KB | Ok |
22 | Correct | 10 ms | 10868 KB | Ok |
23 | Correct | 9 ms | 10868 KB | Ok |
24 | Correct | 12 ms | 23212 KB | Ok |
25 | Correct | 13 ms | 23212 KB | Ok |
26 | Correct | 11 ms | 23212 KB | Ok |
27 | Correct | 11 ms | 23212 KB | Ok |
28 | Correct | 11 ms | 23212 KB | Ok |
29 | Correct | 15 ms | 23212 KB | Ok |
30 | Correct | 11 ms | 23212 KB | Ok |
31 | Correct | 11 ms | 23212 KB | Ok |
32 | Correct | 16 ms | 23212 KB | Ok |
33 | Correct | 11 ms | 23212 KB | Ok |
34 | Correct | 14 ms | 23212 KB | Ok |
35 | Correct | 15 ms | 23212 KB | Ok |
36 | Correct | 18 ms | 23212 KB | Ok |
37 | Correct | 13 ms | 23212 KB | Ok |
38 | Correct | 13 ms | 23212 KB | Ok |
39 | Correct | 14 ms | 23212 KB | Ok |
40 | Correct | 16 ms | 23212 KB | Ok |
41 | Correct | 15 ms | 23212 KB | Ok |
42 | Correct | 14 ms | 23212 KB | Ok |
43 | Correct | 14 ms | 23212 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Ok |
2 | Correct | 9 ms | 9832 KB | Ok |
3 | Correct | 11 ms | 9832 KB | Ok |
4 | Correct | 11 ms | 9832 KB | Ok |
5 | Correct | 10 ms | 9960 KB | Ok |
6 | Correct | 9 ms | 9960 KB | Ok |
7 | Correct | 9 ms | 9960 KB | Ok |
8 | Correct | 9 ms | 10032 KB | Ok |
9 | Correct | 9 ms | 10032 KB | Ok |
10 | Correct | 11 ms | 10032 KB | Ok |
11 | Correct | 9 ms | 10032 KB | Ok |
12 | Correct | 9 ms | 10068 KB | Ok |
13 | Correct | 9 ms | 10068 KB | Ok |
14 | Correct | 9 ms | 10068 KB | Ok |
15 | Correct | 9 ms | 10084 KB | Ok |
16 | Correct | 11 ms | 10084 KB | Ok |
17 | Correct | 9 ms | 10084 KB | Ok |
18 | Correct | 11 ms | 10088 KB | Ok |
19 | Correct | 20 ms | 10648 KB | Ok |
20 | Correct | 14 ms | 10648 KB | Ok |
21 | Correct | 24 ms | 10868 KB | Ok |
22 | Correct | 16 ms | 10868 KB | Ok |
23 | Correct | 10 ms | 10868 KB | Ok |
24 | Correct | 12 ms | 10868 KB | Ok |
25 | Correct | 9 ms | 10868 KB | Ok |
26 | Correct | 10 ms | 10868 KB | Ok |
27 | Correct | 9 ms | 10868 KB | Ok |
28 | Correct | 9 ms | 10868 KB | Ok |
29 | Correct | 9 ms | 10868 KB | Ok |
30 | Correct | 9 ms | 10868 KB | Ok |
31 | Correct | 9 ms | 10868 KB | Ok |
32 | Correct | 10 ms | 10868 KB | Ok |
33 | Correct | 9 ms | 10868 KB | Ok |
34 | Correct | 12 ms | 23212 KB | Ok |
35 | Correct | 13 ms | 23212 KB | Ok |
36 | Correct | 11 ms | 23212 KB | Ok |
37 | Correct | 11 ms | 23212 KB | Ok |
38 | Correct | 11 ms | 23212 KB | Ok |
39 | Correct | 15 ms | 23212 KB | Ok |
40 | Correct | 11 ms | 23212 KB | Ok |
41 | Correct | 11 ms | 23212 KB | Ok |
42 | Correct | 16 ms | 23212 KB | Ok |
43 | Correct | 11 ms | 23212 KB | Ok |
44 | Correct | 14 ms | 23212 KB | Ok |
45 | Correct | 15 ms | 23212 KB | Ok |
46 | Correct | 18 ms | 23212 KB | Ok |
47 | Correct | 13 ms | 23212 KB | Ok |
48 | Correct | 13 ms | 23212 KB | Ok |
49 | Correct | 14 ms | 23212 KB | Ok |
50 | Correct | 16 ms | 23212 KB | Ok |
51 | Correct | 15 ms | 23212 KB | Ok |
52 | Correct | 14 ms | 23212 KB | Ok |
53 | Correct | 14 ms | 23212 KB | Ok |
54 | Correct | 93 ms | 23212 KB | Ok |
55 | Correct | 103 ms | 23212 KB | Ok |
56 | Correct | 99 ms | 23212 KB | Ok |
57 | Correct | 90 ms | 23212 KB | Ok |
58 | Correct | 94 ms | 23212 KB | Ok |
59 | Correct | 93 ms | 23212 KB | Ok |
60 | Correct | 86 ms | 23212 KB | Ok |
61 | Correct | 79 ms | 23212 KB | Ok |
62 | Correct | 100 ms | 23212 KB | Ok |
63 | Correct | 89 ms | 23212 KB | Ok |
64 | Correct | 109 ms | 23212 KB | Ok |
65 | Correct | 101 ms | 23212 KB | Ok |
66 | Correct | 86 ms | 23212 KB | Ok |
67 | Correct | 75 ms | 23212 KB | Ok |
68 | Correct | 121 ms | 23212 KB | Ok |
69 | Correct | 249 ms | 23212 KB | Ok |
70 | Correct | 202 ms | 23212 KB | Ok |
71 | Correct | 187 ms | 23212 KB | Ok |
72 | Correct | 192 ms | 23212 KB | Ok |
73 | Correct | 180 ms | 23212 KB | Ok |
74 | Correct | 184 ms | 23212 KB | Ok |
75 | Correct | 201 ms | 23212 KB | Ok |
76 | Correct | 274 ms | 23212 KB | Ok |
77 | Correct | 174 ms | 23212 KB | Ok |
78 | Correct | 254 ms | 23212 KB | Ok |
79 | Correct | 206 ms | 23212 KB | Ok |
80 | Correct | 206 ms | 23212 KB | Ok |
81 | Correct | 216 ms | 23212 KB | Ok |
82 | Correct | 183 ms | 23212 KB | Ok |
83 | Correct | 163 ms | 23212 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Ok |
2 | Correct | 9 ms | 9832 KB | Ok |
3 | Correct | 11 ms | 9832 KB | Ok |
4 | Correct | 11 ms | 9832 KB | Ok |
5 | Correct | 10 ms | 9960 KB | Ok |
6 | Correct | 9 ms | 9960 KB | Ok |
7 | Correct | 9 ms | 9960 KB | Ok |
8 | Correct | 9 ms | 10032 KB | Ok |
9 | Correct | 9 ms | 10032 KB | Ok |
10 | Correct | 11 ms | 10032 KB | Ok |
11 | Correct | 9 ms | 10032 KB | Ok |
12 | Correct | 9 ms | 10068 KB | Ok |
13 | Correct | 9 ms | 10068 KB | Ok |
14 | Correct | 9 ms | 10068 KB | Ok |
15 | Correct | 9 ms | 10084 KB | Ok |
16 | Correct | 11 ms | 10084 KB | Ok |
17 | Correct | 9 ms | 10084 KB | Ok |
18 | Correct | 11 ms | 10088 KB | Ok |
19 | Correct | 20 ms | 10648 KB | Ok |
20 | Correct | 14 ms | 10648 KB | Ok |
21 | Correct | 24 ms | 10868 KB | Ok |
22 | Correct | 16 ms | 10868 KB | Ok |
23 | Correct | 10 ms | 10868 KB | Ok |
24 | Correct | 12 ms | 10868 KB | Ok |
25 | Correct | 9 ms | 10868 KB | Ok |
26 | Correct | 10 ms | 10868 KB | Ok |
27 | Correct | 9 ms | 10868 KB | Ok |
28 | Correct | 9 ms | 10868 KB | Ok |
29 | Correct | 9 ms | 10868 KB | Ok |
30 | Correct | 9 ms | 10868 KB | Ok |
31 | Correct | 9 ms | 10868 KB | Ok |
32 | Correct | 10 ms | 10868 KB | Ok |
33 | Correct | 9 ms | 10868 KB | Ok |
34 | Correct | 9 ms | 10868 KB | Ok |
35 | Correct | 9 ms | 10868 KB | Ok |
36 | Correct | 9 ms | 10868 KB | Ok |
37 | Correct | 9 ms | 10868 KB | Ok |
38 | Correct | 9 ms | 10868 KB | Ok |
39 | Correct | 113 ms | 20636 KB | Ok |
40 | Correct | 123 ms | 21276 KB | Ok |
41 | Correct | 191 ms | 23212 KB | Ok |
42 | Correct | 161 ms | 23212 KB | Ok |
43 | Correct | 90 ms | 23212 KB | Ok |
44 | Correct | 139 ms | 23212 KB | Ok |
45 | Correct | 12 ms | 23212 KB | Ok |
46 | Correct | 13 ms | 23212 KB | Ok |
47 | Correct | 11 ms | 23212 KB | Ok |
48 | Correct | 11 ms | 23212 KB | Ok |
49 | Correct | 11 ms | 23212 KB | Ok |
50 | Correct | 15 ms | 23212 KB | Ok |
51 | Correct | 11 ms | 23212 KB | Ok |
52 | Correct | 11 ms | 23212 KB | Ok |
53 | Correct | 16 ms | 23212 KB | Ok |
54 | Correct | 11 ms | 23212 KB | Ok |
55 | Correct | 14 ms | 23212 KB | Ok |
56 | Correct | 15 ms | 23212 KB | Ok |
57 | Correct | 18 ms | 23212 KB | Ok |
58 | Correct | 13 ms | 23212 KB | Ok |
59 | Correct | 13 ms | 23212 KB | Ok |
60 | Correct | 14 ms | 23212 KB | Ok |
61 | Correct | 16 ms | 23212 KB | Ok |
62 | Correct | 15 ms | 23212 KB | Ok |
63 | Correct | 14 ms | 23212 KB | Ok |
64 | Correct | 14 ms | 23212 KB | Ok |
65 | Correct | 93 ms | 23212 KB | Ok |
66 | Correct | 103 ms | 23212 KB | Ok |
67 | Correct | 99 ms | 23212 KB | Ok |
68 | Correct | 90 ms | 23212 KB | Ok |
69 | Correct | 94 ms | 23212 KB | Ok |
70 | Correct | 93 ms | 23212 KB | Ok |
71 | Correct | 86 ms | 23212 KB | Ok |
72 | Correct | 79 ms | 23212 KB | Ok |
73 | Correct | 100 ms | 23212 KB | Ok |
74 | Correct | 89 ms | 23212 KB | Ok |
75 | Correct | 109 ms | 23212 KB | Ok |
76 | Correct | 101 ms | 23212 KB | Ok |
77 | Correct | 86 ms | 23212 KB | Ok |
78 | Correct | 75 ms | 23212 KB | Ok |
79 | Correct | 121 ms | 23212 KB | Ok |
80 | Correct | 249 ms | 23212 KB | Ok |
81 | Correct | 202 ms | 23212 KB | Ok |
82 | Correct | 187 ms | 23212 KB | Ok |
83 | Correct | 192 ms | 23212 KB | Ok |
84 | Correct | 180 ms | 23212 KB | Ok |
85 | Correct | 184 ms | 23212 KB | Ok |
86 | Correct | 201 ms | 23212 KB | Ok |
87 | Correct | 274 ms | 23212 KB | Ok |
88 | Correct | 174 ms | 23212 KB | Ok |
89 | Correct | 254 ms | 23212 KB | Ok |
90 | Correct | 206 ms | 23212 KB | Ok |
91 | Correct | 206 ms | 23212 KB | Ok |
92 | Correct | 216 ms | 23212 KB | Ok |
93 | Correct | 183 ms | 23212 KB | Ok |
94 | Correct | 163 ms | 23212 KB | Ok |
95 | Correct | 209 ms | 24716 KB | Ok |
96 | Correct | 326 ms | 31784 KB | Ok |
97 | Correct | 288 ms | 31784 KB | Ok |
98 | Correct | 233 ms | 31784 KB | Ok |
99 | Correct | 267 ms | 31784 KB | Ok |
100 | Correct | 289 ms | 31784 KB | Ok |
101 | Correct | 347 ms | 31784 KB | Ok |
102 | Correct | 257 ms | 31784 KB | Ok |
103 | Correct | 319 ms | 31784 KB | Ok |
104 | Correct | 321 ms | 31784 KB | Ok |
105 | Correct | 324 ms | 31784 KB | Ok |
106 | Correct | 287 ms | 31784 KB | Ok |
107 | Correct | 375 ms | 31784 KB | Ok |
108 | Correct | 303 ms | 31784 KB | Ok |
109 | Correct | 320 ms | 32432 KB | Ok |
110 | Correct | 1131 ms | 46412 KB | Ok |
111 | Correct | 1751 ms | 56028 KB | Ok |
112 | Correct | 1357 ms | 56028 KB | Ok |
113 | Correct | 1386 ms | 56028 KB | Ok |
114 | Correct | 1493 ms | 56028 KB | Ok |
115 | Correct | 1520 ms | 56028 KB | Ok |
116 | Correct | 1447 ms | 56028 KB | Ok |
117 | Correct | 1479 ms | 56028 KB | Ok |
118 | Correct | 1215 ms | 56028 KB | Ok |
119 | Correct | 1536 ms | 56028 KB | Ok |
120 | Correct | 1363 ms | 56028 KB | Ok |
121 | Correct | 1266 ms | 56028 KB | Ok |
122 | Correct | 1407 ms | 56028 KB | Ok |
123 | Correct | 1623 ms | 56168 KB | Ok |
124 | Correct | 1140 ms | 56168 KB | Ok |
125 | Correct | 533 ms | 56168 KB | Ok |