답안 #485538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485538 2021-11-08T05:09:46 Z SirCovidThe19th Nice sequence (IZhO18_sequence) C++17
100 / 100
384 ms 40236 KB
#include <bits/stdc++.h>
using namespace std;

int n, m, ti = 0, sz, pre[1000005], vis[1000005];

void dfs(int cur){
    if (vis[cur]) return;
    vis[cur] = ++ti;
    if (cur - n >= 0) pre[cur - n] = pre[cur] + 1, dfs(cur - n); 
    if (cur + m <= sz) pre[cur + m] = pre[cur] + 1, dfs(cur + m);
}

int main(){
    int tc; cin >> tc;
    while (tc--){
        cin >> n >> m; sz = n + m - __gcd(n, m) - 1;
        ti = 0; fill(vis, vis + sz + 1, 0);

        for (int i = 0; i <= sz; i++) if (!vis[i]) pre[i] = -(++ti), dfs(i);

        cout<<sz<<endl;
        for (int i = 1; i <= sz; i++) cout<<pre[i] - pre[i - 1]<<" ";
        cout<<endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 2 ms 332 KB Ok
7 Correct 8 ms 972 KB Ok
8 Correct 4 ms 584 KB Ok
9 Correct 10 ms 1064 KB Ok
10 Correct 5 ms 716 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 0 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 1 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 71 ms 8644 KB Ok
7 Correct 69 ms 7328 KB Ok
8 Correct 119 ms 10348 KB Ok
9 Correct 90 ms 9412 KB Ok
10 Correct 55 ms 6008 KB Ok
11 Correct 86 ms 11260 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 1 ms 204 KB Ok
16 Correct 0 ms 204 KB Ok
17 Correct 0 ms 204 KB Ok
18 Correct 0 ms 204 KB Ok
19 Correct 0 ms 204 KB Ok
20 Correct 0 ms 204 KB Ok
21 Correct 1 ms 204 KB Ok
22 Correct 1 ms 204 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 2 ms 332 KB Ok
25 Correct 3 ms 460 KB Ok
26 Correct 2 ms 332 KB Ok
27 Correct 2 ms 332 KB Ok
28 Correct 2 ms 332 KB Ok
29 Correct 2 ms 332 KB Ok
30 Correct 1 ms 332 KB Ok
31 Correct 2 ms 332 KB Ok
32 Correct 2 ms 332 KB Ok
33 Correct 2 ms 332 KB Ok
34 Correct 3 ms 460 KB Ok
35 Correct 3 ms 588 KB Ok
36 Correct 4 ms 460 KB Ok
37 Correct 3 ms 588 KB Ok
38 Correct 4 ms 460 KB Ok
39 Correct 3 ms 460 KB Ok
40 Correct 4 ms 588 KB Ok
41 Correct 4 ms 460 KB Ok
42 Correct 4 ms 552 KB Ok
43 Correct 3 ms 588 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 1 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Correct 1 ms 204 KB Ok
17 Correct 1 ms 204 KB Ok
18 Correct 2 ms 332 KB Ok
19 Correct 8 ms 972 KB Ok
20 Correct 4 ms 584 KB Ok
21 Correct 10 ms 1064 KB Ok
22 Correct 5 ms 716 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 1 ms 204 KB Ok
26 Correct 0 ms 204 KB Ok
27 Correct 0 ms 204 KB Ok
28 Correct 0 ms 204 KB Ok
29 Correct 0 ms 204 KB Ok
30 Correct 0 ms 204 KB Ok
31 Correct 1 ms 204 KB Ok
32 Correct 1 ms 204 KB Ok
33 Correct 0 ms 204 KB Ok
34 Correct 2 ms 332 KB Ok
35 Correct 3 ms 460 KB Ok
36 Correct 2 ms 332 KB Ok
37 Correct 2 ms 332 KB Ok
38 Correct 2 ms 332 KB Ok
39 Correct 2 ms 332 KB Ok
40 Correct 1 ms 332 KB Ok
41 Correct 2 ms 332 KB Ok
42 Correct 2 ms 332 KB Ok
43 Correct 2 ms 332 KB Ok
44 Correct 3 ms 460 KB Ok
45 Correct 3 ms 588 KB Ok
46 Correct 4 ms 460 KB Ok
47 Correct 3 ms 588 KB Ok
48 Correct 4 ms 460 KB Ok
49 Correct 3 ms 460 KB Ok
50 Correct 4 ms 588 KB Ok
51 Correct 4 ms 460 KB Ok
52 Correct 4 ms 552 KB Ok
53 Correct 3 ms 588 KB Ok
54 Correct 61 ms 3140 KB Ok
55 Correct 64 ms 3552 KB Ok
56 Correct 67 ms 3480 KB Ok
57 Correct 47 ms 2732 KB Ok
58 Correct 57 ms 3360 KB Ok
59 Correct 56 ms 3268 KB Ok
60 Correct 50 ms 2884 KB Ok
61 Correct 50 ms 2908 KB Ok
62 Correct 64 ms 3740 KB Ok
63 Correct 52 ms 3184 KB Ok
64 Correct 62 ms 3560 KB Ok
65 Correct 71 ms 3396 KB Ok
66 Correct 55 ms 3140 KB Ok
67 Correct 48 ms 2808 KB Ok
68 Correct 55 ms 3352 KB Ok
69 Correct 90 ms 9460 KB Ok
70 Correct 92 ms 9728 KB Ok
71 Correct 89 ms 8296 KB Ok
72 Correct 88 ms 9540 KB Ok
73 Correct 96 ms 8544 KB Ok
74 Correct 88 ms 8976 KB Ok
75 Correct 90 ms 9248 KB Ok
76 Correct 87 ms 9536 KB Ok
77 Correct 88 ms 8772 KB Ok
78 Correct 89 ms 9444 KB Ok
79 Correct 90 ms 9156 KB Ok
80 Correct 93 ms 8416 KB Ok
81 Correct 96 ms 9680 KB Ok
82 Correct 89 ms 9000 KB Ok
83 Correct 88 ms 9540 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 1 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Correct 1 ms 204 KB Ok
17 Correct 1 ms 204 KB Ok
18 Correct 2 ms 332 KB Ok
19 Correct 8 ms 972 KB Ok
20 Correct 4 ms 584 KB Ok
21 Correct 10 ms 1064 KB Ok
22 Correct 5 ms 716 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 1 ms 204 KB Ok
26 Correct 0 ms 204 KB Ok
27 Correct 0 ms 204 KB Ok
28 Correct 0 ms 204 KB Ok
29 Correct 0 ms 204 KB Ok
30 Correct 0 ms 204 KB Ok
31 Correct 1 ms 204 KB Ok
32 Correct 1 ms 204 KB Ok
33 Correct 0 ms 204 KB Ok
34 Correct 0 ms 204 KB Ok
35 Correct 1 ms 204 KB Ok
36 Correct 1 ms 204 KB Ok
37 Correct 1 ms 204 KB Ok
38 Correct 0 ms 204 KB Ok
39 Correct 71 ms 8644 KB Ok
40 Correct 69 ms 7328 KB Ok
41 Correct 119 ms 10348 KB Ok
42 Correct 90 ms 9412 KB Ok
43 Correct 55 ms 6008 KB Ok
44 Correct 86 ms 11260 KB Ok
45 Correct 2 ms 332 KB Ok
46 Correct 3 ms 460 KB Ok
47 Correct 2 ms 332 KB Ok
48 Correct 2 ms 332 KB Ok
49 Correct 2 ms 332 KB Ok
50 Correct 2 ms 332 KB Ok
51 Correct 1 ms 332 KB Ok
52 Correct 2 ms 332 KB Ok
53 Correct 2 ms 332 KB Ok
54 Correct 2 ms 332 KB Ok
55 Correct 3 ms 460 KB Ok
56 Correct 3 ms 588 KB Ok
57 Correct 4 ms 460 KB Ok
58 Correct 3 ms 588 KB Ok
59 Correct 4 ms 460 KB Ok
60 Correct 3 ms 460 KB Ok
61 Correct 4 ms 588 KB Ok
62 Correct 4 ms 460 KB Ok
63 Correct 4 ms 552 KB Ok
64 Correct 3 ms 588 KB Ok
65 Correct 61 ms 3140 KB Ok
66 Correct 64 ms 3552 KB Ok
67 Correct 67 ms 3480 KB Ok
68 Correct 47 ms 2732 KB Ok
69 Correct 57 ms 3360 KB Ok
70 Correct 56 ms 3268 KB Ok
71 Correct 50 ms 2884 KB Ok
72 Correct 50 ms 2908 KB Ok
73 Correct 64 ms 3740 KB Ok
74 Correct 52 ms 3184 KB Ok
75 Correct 62 ms 3560 KB Ok
76 Correct 71 ms 3396 KB Ok
77 Correct 55 ms 3140 KB Ok
78 Correct 48 ms 2808 KB Ok
79 Correct 55 ms 3352 KB Ok
80 Correct 90 ms 9460 KB Ok
81 Correct 92 ms 9728 KB Ok
82 Correct 89 ms 8296 KB Ok
83 Correct 88 ms 9540 KB Ok
84 Correct 96 ms 8544 KB Ok
85 Correct 88 ms 8976 KB Ok
86 Correct 90 ms 9248 KB Ok
87 Correct 87 ms 9536 KB Ok
88 Correct 88 ms 8772 KB Ok
89 Correct 89 ms 9444 KB Ok
90 Correct 90 ms 9156 KB Ok
91 Correct 93 ms 8416 KB Ok
92 Correct 96 ms 9680 KB Ok
93 Correct 89 ms 9000 KB Ok
94 Correct 88 ms 9540 KB Ok
95 Correct 141 ms 8004 KB Ok
96 Correct 196 ms 11392 KB Ok
97 Correct 193 ms 10392 KB Ok
98 Correct 149 ms 8604 KB Ok
99 Correct 178 ms 9184 KB Ok
100 Correct 185 ms 9964 KB Ok
101 Correct 184 ms 9796 KB Ok
102 Correct 171 ms 9764 KB Ok
103 Correct 171 ms 10176 KB Ok
104 Correct 213 ms 11216 KB Ok
105 Correct 193 ms 11332 KB Ok
106 Correct 168 ms 9668 KB Ok
107 Correct 191 ms 10436 KB Ok
108 Correct 207 ms 11828 KB Ok
109 Correct 192 ms 10700 KB Ok
110 Correct 377 ms 38728 KB Ok
111 Correct 381 ms 40048 KB Ok
112 Correct 361 ms 37068 KB Ok
113 Correct 366 ms 38724 KB Ok
114 Correct 371 ms 36648 KB Ok
115 Correct 373 ms 40236 KB Ok
116 Correct 378 ms 40000 KB Ok
117 Correct 363 ms 39640 KB Ok
118 Correct 367 ms 35768 KB Ok
119 Correct 384 ms 39236 KB Ok
120 Correct 376 ms 39620 KB Ok
121 Correct 365 ms 37928 KB Ok
122 Correct 379 ms 40132 KB Ok
123 Correct 374 ms 38792 KB Ok
124 Correct 365 ms 36548 KB Ok
125 Correct 326 ms 22800 KB Ok