Submission #93883

# Submission time Handle Problem Language Result Execution time Memory
93883 2019-01-12T19:46:47 Z dalgerok Nice sequence (IZhO18_sequence) C++14
100 / 100
408 ms 35476 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 4e5 + 5;




int n, m, pref[N], timer, ans;


void dfs(int v){
    if(v - m >= 0 && pref[v - m] == 0){
        dfs(v - m);
    }
    if(v + n <= ans && pref[v + n] == 0){
        dfs(v + n);
    }
    pref[v] = ++timer;
}

void solve(){
    cin >> n >> m;
    ans = n + m - 1 - __gcd(n, m);
    memset(pref, 0, sizeof(pref));
    timer = 0;
    for(int i = 0; i <= ans; i++){
        if(!pref[i]){
            dfs(i);
        }
    }
    cout << ans << "\n";
    for(int i = 1; i <= ans; i++){
        cout << pref[i] - pref[i - 1] << " ";
    }
    if(ans > 0){
        cout << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int test;
    cin >> test;
    for(int i = 1; i <= test; i++){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Ok
2 Correct 4 ms 1912 KB Ok
3 Correct 4 ms 1912 KB Ok
4 Correct 4 ms 1912 KB Ok
5 Correct 4 ms 1912 KB Ok
6 Correct 4 ms 1916 KB Ok
7 Correct 4 ms 1912 KB Ok
8 Correct 4 ms 1912 KB Ok
9 Correct 4 ms 1912 KB Ok
10 Correct 4 ms 1912 KB Ok
11 Correct 4 ms 1912 KB Ok
12 Correct 4 ms 1912 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Ok
2 Correct 4 ms 1912 KB Ok
3 Correct 3 ms 1912 KB Ok
4 Correct 3 ms 1912 KB Ok
5 Correct 4 ms 1912 KB Ok
6 Correct 5 ms 1912 KB Ok
7 Correct 9 ms 2296 KB Ok
8 Correct 6 ms 2168 KB Ok
9 Correct 11 ms 2424 KB Ok
10 Correct 8 ms 2216 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1912 KB Ok
2 Correct 4 ms 1912 KB Ok
3 Correct 4 ms 1912 KB Ok
4 Correct 4 ms 1912 KB Ok
5 Correct 1 ms 1912 KB Ok
6 Correct 4 ms 1912 KB Ok
7 Correct 3 ms 1912 KB Ok
8 Correct 4 ms 1912 KB Ok
9 Correct 3 ms 1912 KB Ok
10 Correct 3 ms 1912 KB Ok
11 Correct 4 ms 1912 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1912 KB Ok
2 Correct 3 ms 1912 KB Ok
3 Correct 4 ms 1912 KB Ok
4 Correct 3 ms 1912 KB Ok
5 Correct 4 ms 1916 KB Ok
6 Correct 56 ms 6264 KB Ok
7 Correct 48 ms 7032 KB Ok
8 Correct 97 ms 10104 KB Ok
9 Correct 71 ms 9080 KB Ok
10 Correct 43 ms 4728 KB Ok
11 Correct 66 ms 6904 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Ok
2 Correct 4 ms 1912 KB Ok
3 Correct 4 ms 1912 KB Ok
4 Correct 4 ms 1912 KB Ok
5 Correct 4 ms 1912 KB Ok
6 Correct 4 ms 1916 KB Ok
7 Correct 4 ms 1912 KB Ok
8 Correct 4 ms 1912 KB Ok
9 Correct 4 ms 1912 KB Ok
10 Correct 4 ms 1912 KB Ok
11 Correct 4 ms 1912 KB Ok
12 Correct 4 ms 1912 KB Ok
13 Correct 3 ms 1912 KB Ok
14 Correct 4 ms 1912 KB Ok
15 Correct 4 ms 1912 KB Ok
16 Correct 4 ms 1912 KB Ok
17 Correct 1 ms 1912 KB Ok
18 Correct 4 ms 1912 KB Ok
19 Correct 3 ms 1912 KB Ok
20 Correct 4 ms 1912 KB Ok
21 Correct 3 ms 1912 KB Ok
22 Correct 3 ms 1912 KB Ok
23 Correct 4 ms 1912 KB Ok
24 Correct 5 ms 1912 KB Ok
25 Correct 5 ms 1912 KB Ok
26 Correct 5 ms 1912 KB Ok
27 Correct 5 ms 1912 KB Ok
28 Correct 4 ms 1912 KB Ok
29 Correct 5 ms 1912 KB Ok
30 Correct 5 ms 1912 KB Ok
31 Correct 5 ms 1912 KB Ok
32 Correct 5 ms 1912 KB Ok
33 Correct 5 ms 1868 KB Ok
34 Correct 6 ms 2040 KB Ok
35 Correct 6 ms 2168 KB Ok
36 Correct 6 ms 2012 KB Ok
37 Correct 6 ms 2040 KB Ok
38 Correct 6 ms 2044 KB Ok
39 Correct 6 ms 2040 KB Ok
40 Correct 6 ms 2124 KB Ok
41 Correct 6 ms 2168 KB Ok
42 Correct 6 ms 2040 KB Ok
43 Correct 6 ms 2040 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Ok
2 Correct 4 ms 1912 KB Ok
3 Correct 4 ms 1912 KB Ok
4 Correct 4 ms 1912 KB Ok
5 Correct 4 ms 1912 KB Ok
6 Correct 4 ms 1916 KB Ok
7 Correct 4 ms 1912 KB Ok
8 Correct 4 ms 1912 KB Ok
9 Correct 4 ms 1912 KB Ok
10 Correct 4 ms 1912 KB Ok
11 Correct 4 ms 1912 KB Ok
12 Correct 4 ms 1912 KB Ok
13 Correct 4 ms 1912 KB Ok
14 Correct 4 ms 1912 KB Ok
15 Correct 3 ms 1912 KB Ok
16 Correct 3 ms 1912 KB Ok
17 Correct 4 ms 1912 KB Ok
18 Correct 5 ms 1912 KB Ok
19 Correct 9 ms 2296 KB Ok
20 Correct 6 ms 2168 KB Ok
21 Correct 11 ms 2424 KB Ok
22 Correct 8 ms 2216 KB Ok
23 Correct 3 ms 1912 KB Ok
24 Correct 4 ms 1912 KB Ok
25 Correct 4 ms 1912 KB Ok
26 Correct 4 ms 1912 KB Ok
27 Correct 1 ms 1912 KB Ok
28 Correct 4 ms 1912 KB Ok
29 Correct 3 ms 1912 KB Ok
30 Correct 4 ms 1912 KB Ok
31 Correct 3 ms 1912 KB Ok
32 Correct 3 ms 1912 KB Ok
33 Correct 4 ms 1912 KB Ok
34 Correct 5 ms 1912 KB Ok
35 Correct 5 ms 1912 KB Ok
36 Correct 5 ms 1912 KB Ok
37 Correct 5 ms 1912 KB Ok
38 Correct 4 ms 1912 KB Ok
39 Correct 5 ms 1912 KB Ok
40 Correct 5 ms 1912 KB Ok
41 Correct 5 ms 1912 KB Ok
42 Correct 5 ms 1912 KB Ok
43 Correct 5 ms 1868 KB Ok
44 Correct 6 ms 2040 KB Ok
45 Correct 6 ms 2168 KB Ok
46 Correct 6 ms 2012 KB Ok
47 Correct 6 ms 2040 KB Ok
48 Correct 6 ms 2044 KB Ok
49 Correct 6 ms 2040 KB Ok
50 Correct 6 ms 2124 KB Ok
51 Correct 6 ms 2168 KB Ok
52 Correct 6 ms 2040 KB Ok
53 Correct 6 ms 2040 KB Ok
54 Correct 46 ms 3524 KB Ok
55 Correct 54 ms 3832 KB Ok
56 Correct 55 ms 3900 KB Ok
57 Correct 38 ms 3192 KB Ok
58 Correct 45 ms 3320 KB Ok
59 Correct 47 ms 3320 KB Ok
60 Correct 40 ms 3064 KB Ok
61 Correct 40 ms 3192 KB Ok
62 Correct 53 ms 3636 KB Ok
63 Correct 45 ms 3412 KB Ok
64 Correct 52 ms 3828 KB Ok
65 Correct 48 ms 3460 KB Ok
66 Correct 47 ms 3288 KB Ok
67 Correct 43 ms 3240 KB Ok
68 Correct 45 ms 3312 KB Ok
69 Correct 92 ms 9208 KB Ok
70 Correct 94 ms 9848 KB Ok
71 Correct 92 ms 9400 KB Ok
72 Correct 91 ms 9192 KB Ok
73 Correct 95 ms 9080 KB Ok
74 Correct 93 ms 8824 KB Ok
75 Correct 89 ms 8696 KB Ok
76 Correct 97 ms 9464 KB Ok
77 Correct 88 ms 8568 KB Ok
78 Correct 99 ms 8952 KB Ok
79 Correct 99 ms 9280 KB Ok
80 Correct 94 ms 9336 KB Ok
81 Correct 91 ms 9080 KB Ok
82 Correct 91 ms 9208 KB Ok
83 Correct 88 ms 8696 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Ok
2 Correct 4 ms 1912 KB Ok
3 Correct 4 ms 1912 KB Ok
4 Correct 4 ms 1912 KB Ok
5 Correct 4 ms 1912 KB Ok
6 Correct 4 ms 1916 KB Ok
7 Correct 4 ms 1912 KB Ok
8 Correct 4 ms 1912 KB Ok
9 Correct 4 ms 1912 KB Ok
10 Correct 4 ms 1912 KB Ok
11 Correct 4 ms 1912 KB Ok
12 Correct 4 ms 1912 KB Ok
13 Correct 4 ms 1912 KB Ok
14 Correct 4 ms 1912 KB Ok
15 Correct 3 ms 1912 KB Ok
16 Correct 3 ms 1912 KB Ok
17 Correct 4 ms 1912 KB Ok
18 Correct 5 ms 1912 KB Ok
19 Correct 9 ms 2296 KB Ok
20 Correct 6 ms 2168 KB Ok
21 Correct 11 ms 2424 KB Ok
22 Correct 8 ms 2216 KB Ok
23 Correct 3 ms 1912 KB Ok
24 Correct 4 ms 1912 KB Ok
25 Correct 4 ms 1912 KB Ok
26 Correct 4 ms 1912 KB Ok
27 Correct 1 ms 1912 KB Ok
28 Correct 4 ms 1912 KB Ok
29 Correct 3 ms 1912 KB Ok
30 Correct 4 ms 1912 KB Ok
31 Correct 3 ms 1912 KB Ok
32 Correct 3 ms 1912 KB Ok
33 Correct 4 ms 1912 KB Ok
34 Correct 3 ms 1912 KB Ok
35 Correct 3 ms 1912 KB Ok
36 Correct 4 ms 1912 KB Ok
37 Correct 3 ms 1912 KB Ok
38 Correct 4 ms 1916 KB Ok
39 Correct 56 ms 6264 KB Ok
40 Correct 48 ms 7032 KB Ok
41 Correct 97 ms 10104 KB Ok
42 Correct 71 ms 9080 KB Ok
43 Correct 43 ms 4728 KB Ok
44 Correct 66 ms 6904 KB Ok
45 Correct 5 ms 1912 KB Ok
46 Correct 5 ms 1912 KB Ok
47 Correct 5 ms 1912 KB Ok
48 Correct 5 ms 1912 KB Ok
49 Correct 4 ms 1912 KB Ok
50 Correct 5 ms 1912 KB Ok
51 Correct 5 ms 1912 KB Ok
52 Correct 5 ms 1912 KB Ok
53 Correct 5 ms 1912 KB Ok
54 Correct 5 ms 1868 KB Ok
55 Correct 6 ms 2040 KB Ok
56 Correct 6 ms 2168 KB Ok
57 Correct 6 ms 2012 KB Ok
58 Correct 6 ms 2040 KB Ok
59 Correct 6 ms 2044 KB Ok
60 Correct 6 ms 2040 KB Ok
61 Correct 6 ms 2124 KB Ok
62 Correct 6 ms 2168 KB Ok
63 Correct 6 ms 2040 KB Ok
64 Correct 6 ms 2040 KB Ok
65 Correct 46 ms 3524 KB Ok
66 Correct 54 ms 3832 KB Ok
67 Correct 55 ms 3900 KB Ok
68 Correct 38 ms 3192 KB Ok
69 Correct 45 ms 3320 KB Ok
70 Correct 47 ms 3320 KB Ok
71 Correct 40 ms 3064 KB Ok
72 Correct 40 ms 3192 KB Ok
73 Correct 53 ms 3636 KB Ok
74 Correct 45 ms 3412 KB Ok
75 Correct 52 ms 3828 KB Ok
76 Correct 48 ms 3460 KB Ok
77 Correct 47 ms 3288 KB Ok
78 Correct 43 ms 3240 KB Ok
79 Correct 45 ms 3312 KB Ok
80 Correct 92 ms 9208 KB Ok
81 Correct 94 ms 9848 KB Ok
82 Correct 92 ms 9400 KB Ok
83 Correct 91 ms 9192 KB Ok
84 Correct 95 ms 9080 KB Ok
85 Correct 93 ms 8824 KB Ok
86 Correct 89 ms 8696 KB Ok
87 Correct 97 ms 9464 KB Ok
88 Correct 88 ms 8568 KB Ok
89 Correct 99 ms 8952 KB Ok
90 Correct 99 ms 9280 KB Ok
91 Correct 94 ms 9336 KB Ok
92 Correct 91 ms 9080 KB Ok
93 Correct 91 ms 9208 KB Ok
94 Correct 88 ms 8696 KB Ok
95 Correct 114 ms 6092 KB Ok
96 Correct 160 ms 7456 KB Ok
97 Correct 147 ms 7072 KB Ok
98 Correct 116 ms 5756 KB Ok
99 Correct 139 ms 6392 KB Ok
100 Correct 136 ms 6680 KB Ok
101 Correct 143 ms 6648 KB Ok
102 Correct 135 ms 6844 KB Ok
103 Correct 138 ms 6672 KB Ok
104 Correct 159 ms 7896 KB Ok
105 Correct 150 ms 7292 KB Ok
106 Correct 134 ms 6956 KB Ok
107 Correct 145 ms 7032 KB Ok
108 Correct 164 ms 7672 KB Ok
109 Correct 148 ms 7288 KB Ok
110 Correct 378 ms 32300 KB Ok
111 Correct 408 ms 34712 KB Ok
112 Correct 393 ms 33216 KB Ok
113 Correct 391 ms 34384 KB Ok
114 Correct 393 ms 35476 KB Ok
115 Correct 380 ms 33016 KB Ok
116 Correct 389 ms 34828 KB Ok
117 Correct 368 ms 33688 KB Ok
118 Correct 368 ms 33904 KB Ok
119 Correct 370 ms 33400 KB Ok
120 Correct 392 ms 33400 KB Ok
121 Correct 373 ms 32452 KB Ok
122 Correct 385 ms 33912 KB Ok
123 Correct 392 ms 34688 KB Ok
124 Correct 377 ms 31096 KB Ok
125 Correct 255 ms 17912 KB Ok