답안 #85428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85428 2018-11-19T20:38:48 Z farukkastamonuda Nice sequence (IZhO18_sequence) C++14
100 / 100
570 ms 42012 KB
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
 
const int MAXN = 400001;
 
bool w[MAXN];
int ans;
int a[MAXN];
int t;
int n, m;
 
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
 
void dfs(int v) {
    if (v < 0 || v > ans || w[v]) {
        return;
    }
 
    w[v] = true;
    dfs(v - n);
    dfs(v + m);
    
    a[v] = t++;
}
 
void solve() {
    cin >> n >> m;
    ans = n + m - gcd(n, m) - 1;
    t = 0;
    fill(w, w + ans + 1, false);
 
    for (int i = 0; i <= ans; ++i) {
        dfs(i);
    }
 
    cout << ans << "\n";
    for (int i = 0; i < ans; ++i) {
        cout << a[i] - a[i + 1] << " ";
    }
 
    cout << "\n";
}
 
int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 500 KB Ok
3 Correct 2 ms 548 KB Ok
4 Correct 2 ms 548 KB Ok
5 Correct 3 ms 548 KB Ok
6 Correct 2 ms 548 KB Ok
7 Correct 2 ms 548 KB Ok
8 Correct 3 ms 548 KB Ok
9 Correct 2 ms 632 KB Ok
10 Correct 2 ms 632 KB Ok
11 Correct 2 ms 632 KB Ok
12 Correct 2 ms 724 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Ok
2 Correct 2 ms 748 KB Ok
3 Correct 2 ms 748 KB Ok
4 Correct 2 ms 748 KB Ok
5 Correct 2 ms 748 KB Ok
6 Correct 4 ms 748 KB Ok
7 Correct 10 ms 1148 KB Ok
8 Correct 6 ms 1148 KB Ok
9 Correct 11 ms 1292 KB Ok
10 Correct 7 ms 1292 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1292 KB Ok
2 Correct 2 ms 1292 KB Ok
3 Correct 2 ms 1292 KB Ok
4 Correct 2 ms 1292 KB Ok
5 Correct 2 ms 1292 KB Ok
6 Correct 2 ms 1292 KB Ok
7 Correct 2 ms 1292 KB Ok
8 Correct 2 ms 1292 KB Ok
9 Correct 2 ms 1292 KB Ok
10 Correct 2 ms 1292 KB Ok
11 Correct 2 ms 1292 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1292 KB Ok
2 Correct 2 ms 1292 KB Ok
3 Correct 2 ms 1292 KB Ok
4 Correct 2 ms 1292 KB Ok
5 Correct 2 ms 1292 KB Ok
6 Correct 112 ms 9576 KB Ok
7 Correct 92 ms 9576 KB Ok
8 Correct 121 ms 11460 KB Ok
9 Correct 100 ms 11460 KB Ok
10 Correct 71 ms 11460 KB Ok
11 Correct 93 ms 12588 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 500 KB Ok
3 Correct 2 ms 548 KB Ok
4 Correct 2 ms 548 KB Ok
5 Correct 3 ms 548 KB Ok
6 Correct 2 ms 548 KB Ok
7 Correct 2 ms 548 KB Ok
8 Correct 3 ms 548 KB Ok
9 Correct 2 ms 632 KB Ok
10 Correct 2 ms 632 KB Ok
11 Correct 2 ms 632 KB Ok
12 Correct 2 ms 724 KB Ok
13 Correct 2 ms 1292 KB Ok
14 Correct 2 ms 1292 KB Ok
15 Correct 2 ms 1292 KB Ok
16 Correct 2 ms 1292 KB Ok
17 Correct 2 ms 1292 KB Ok
18 Correct 2 ms 1292 KB Ok
19 Correct 2 ms 1292 KB Ok
20 Correct 2 ms 1292 KB Ok
21 Correct 2 ms 1292 KB Ok
22 Correct 2 ms 1292 KB Ok
23 Correct 2 ms 1292 KB Ok
24 Correct 7 ms 12588 KB Ok
25 Correct 5 ms 12588 KB Ok
26 Correct 3 ms 12588 KB Ok
27 Correct 3 ms 12588 KB Ok
28 Correct 3 ms 12588 KB Ok
29 Correct 5 ms 12588 KB Ok
30 Correct 5 ms 12588 KB Ok
31 Correct 3 ms 12588 KB Ok
32 Correct 4 ms 12588 KB Ok
33 Correct 3 ms 12588 KB Ok
34 Correct 5 ms 12588 KB Ok
35 Correct 5 ms 12588 KB Ok
36 Correct 5 ms 12588 KB Ok
37 Correct 5 ms 12588 KB Ok
38 Correct 5 ms 12588 KB Ok
39 Correct 5 ms 12588 KB Ok
40 Correct 5 ms 12588 KB Ok
41 Correct 5 ms 12588 KB Ok
42 Correct 6 ms 12588 KB Ok
43 Correct 5 ms 12588 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 500 KB Ok
3 Correct 2 ms 548 KB Ok
4 Correct 2 ms 548 KB Ok
5 Correct 3 ms 548 KB Ok
6 Correct 2 ms 548 KB Ok
7 Correct 2 ms 548 KB Ok
8 Correct 3 ms 548 KB Ok
9 Correct 2 ms 632 KB Ok
10 Correct 2 ms 632 KB Ok
11 Correct 2 ms 632 KB Ok
12 Correct 2 ms 724 KB Ok
13 Correct 2 ms 724 KB Ok
14 Correct 2 ms 748 KB Ok
15 Correct 2 ms 748 KB Ok
16 Correct 2 ms 748 KB Ok
17 Correct 2 ms 748 KB Ok
18 Correct 4 ms 748 KB Ok
19 Correct 10 ms 1148 KB Ok
20 Correct 6 ms 1148 KB Ok
21 Correct 11 ms 1292 KB Ok
22 Correct 7 ms 1292 KB Ok
23 Correct 2 ms 1292 KB Ok
24 Correct 2 ms 1292 KB Ok
25 Correct 2 ms 1292 KB Ok
26 Correct 2 ms 1292 KB Ok
27 Correct 2 ms 1292 KB Ok
28 Correct 2 ms 1292 KB Ok
29 Correct 2 ms 1292 KB Ok
30 Correct 2 ms 1292 KB Ok
31 Correct 2 ms 1292 KB Ok
32 Correct 2 ms 1292 KB Ok
33 Correct 2 ms 1292 KB Ok
34 Correct 7 ms 12588 KB Ok
35 Correct 5 ms 12588 KB Ok
36 Correct 3 ms 12588 KB Ok
37 Correct 3 ms 12588 KB Ok
38 Correct 3 ms 12588 KB Ok
39 Correct 5 ms 12588 KB Ok
40 Correct 5 ms 12588 KB Ok
41 Correct 3 ms 12588 KB Ok
42 Correct 4 ms 12588 KB Ok
43 Correct 3 ms 12588 KB Ok
44 Correct 5 ms 12588 KB Ok
45 Correct 5 ms 12588 KB Ok
46 Correct 5 ms 12588 KB Ok
47 Correct 5 ms 12588 KB Ok
48 Correct 5 ms 12588 KB Ok
49 Correct 5 ms 12588 KB Ok
50 Correct 5 ms 12588 KB Ok
51 Correct 5 ms 12588 KB Ok
52 Correct 6 ms 12588 KB Ok
53 Correct 5 ms 12588 KB Ok
54 Correct 58 ms 12588 KB Ok
55 Correct 68 ms 12588 KB Ok
56 Correct 65 ms 12588 KB Ok
57 Correct 52 ms 12588 KB Ok
58 Correct 63 ms 12588 KB Ok
59 Correct 58 ms 12588 KB Ok
60 Correct 53 ms 12588 KB Ok
61 Correct 51 ms 12588 KB Ok
62 Correct 69 ms 12588 KB Ok
63 Correct 58 ms 12588 KB Ok
64 Correct 71 ms 12588 KB Ok
65 Correct 70 ms 12588 KB Ok
66 Correct 57 ms 12588 KB Ok
67 Correct 55 ms 12588 KB Ok
68 Correct 59 ms 12588 KB Ok
69 Correct 117 ms 12588 KB Ok
70 Correct 117 ms 12588 KB Ok
71 Correct 121 ms 12588 KB Ok
72 Correct 114 ms 12588 KB Ok
73 Correct 116 ms 12588 KB Ok
74 Correct 113 ms 12588 KB Ok
75 Correct 117 ms 12588 KB Ok
76 Correct 129 ms 12588 KB Ok
77 Correct 116 ms 12588 KB Ok
78 Correct 112 ms 12588 KB Ok
79 Correct 116 ms 12588 KB Ok
80 Correct 118 ms 12588 KB Ok
81 Correct 116 ms 12588 KB Ok
82 Correct 109 ms 12588 KB Ok
83 Correct 115 ms 12588 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 500 KB Ok
3 Correct 2 ms 548 KB Ok
4 Correct 2 ms 548 KB Ok
5 Correct 3 ms 548 KB Ok
6 Correct 2 ms 548 KB Ok
7 Correct 2 ms 548 KB Ok
8 Correct 3 ms 548 KB Ok
9 Correct 2 ms 632 KB Ok
10 Correct 2 ms 632 KB Ok
11 Correct 2 ms 632 KB Ok
12 Correct 2 ms 724 KB Ok
13 Correct 2 ms 724 KB Ok
14 Correct 2 ms 748 KB Ok
15 Correct 2 ms 748 KB Ok
16 Correct 2 ms 748 KB Ok
17 Correct 2 ms 748 KB Ok
18 Correct 4 ms 748 KB Ok
19 Correct 10 ms 1148 KB Ok
20 Correct 6 ms 1148 KB Ok
21 Correct 11 ms 1292 KB Ok
22 Correct 7 ms 1292 KB Ok
23 Correct 2 ms 1292 KB Ok
24 Correct 2 ms 1292 KB Ok
25 Correct 2 ms 1292 KB Ok
26 Correct 2 ms 1292 KB Ok
27 Correct 2 ms 1292 KB Ok
28 Correct 2 ms 1292 KB Ok
29 Correct 2 ms 1292 KB Ok
30 Correct 2 ms 1292 KB Ok
31 Correct 2 ms 1292 KB Ok
32 Correct 2 ms 1292 KB Ok
33 Correct 2 ms 1292 KB Ok
34 Correct 2 ms 1292 KB Ok
35 Correct 2 ms 1292 KB Ok
36 Correct 2 ms 1292 KB Ok
37 Correct 2 ms 1292 KB Ok
38 Correct 2 ms 1292 KB Ok
39 Correct 112 ms 9576 KB Ok
40 Correct 92 ms 9576 KB Ok
41 Correct 121 ms 11460 KB Ok
42 Correct 100 ms 11460 KB Ok
43 Correct 71 ms 11460 KB Ok
44 Correct 93 ms 12588 KB Ok
45 Correct 7 ms 12588 KB Ok
46 Correct 5 ms 12588 KB Ok
47 Correct 3 ms 12588 KB Ok
48 Correct 3 ms 12588 KB Ok
49 Correct 3 ms 12588 KB Ok
50 Correct 5 ms 12588 KB Ok
51 Correct 5 ms 12588 KB Ok
52 Correct 3 ms 12588 KB Ok
53 Correct 4 ms 12588 KB Ok
54 Correct 3 ms 12588 KB Ok
55 Correct 5 ms 12588 KB Ok
56 Correct 5 ms 12588 KB Ok
57 Correct 5 ms 12588 KB Ok
58 Correct 5 ms 12588 KB Ok
59 Correct 5 ms 12588 KB Ok
60 Correct 5 ms 12588 KB Ok
61 Correct 5 ms 12588 KB Ok
62 Correct 5 ms 12588 KB Ok
63 Correct 6 ms 12588 KB Ok
64 Correct 5 ms 12588 KB Ok
65 Correct 58 ms 12588 KB Ok
66 Correct 68 ms 12588 KB Ok
67 Correct 65 ms 12588 KB Ok
68 Correct 52 ms 12588 KB Ok
69 Correct 63 ms 12588 KB Ok
70 Correct 58 ms 12588 KB Ok
71 Correct 53 ms 12588 KB Ok
72 Correct 51 ms 12588 KB Ok
73 Correct 69 ms 12588 KB Ok
74 Correct 58 ms 12588 KB Ok
75 Correct 71 ms 12588 KB Ok
76 Correct 70 ms 12588 KB Ok
77 Correct 57 ms 12588 KB Ok
78 Correct 55 ms 12588 KB Ok
79 Correct 59 ms 12588 KB Ok
80 Correct 117 ms 12588 KB Ok
81 Correct 117 ms 12588 KB Ok
82 Correct 121 ms 12588 KB Ok
83 Correct 114 ms 12588 KB Ok
84 Correct 116 ms 12588 KB Ok
85 Correct 113 ms 12588 KB Ok
86 Correct 117 ms 12588 KB Ok
87 Correct 129 ms 12588 KB Ok
88 Correct 116 ms 12588 KB Ok
89 Correct 112 ms 12588 KB Ok
90 Correct 116 ms 12588 KB Ok
91 Correct 118 ms 12588 KB Ok
92 Correct 116 ms 12588 KB Ok
93 Correct 109 ms 12588 KB Ok
94 Correct 115 ms 12588 KB Ok
95 Correct 142 ms 12588 KB Ok
96 Correct 221 ms 12588 KB Ok
97 Correct 198 ms 12588 KB Ok
98 Correct 157 ms 12588 KB Ok
99 Correct 189 ms 12588 KB Ok
100 Correct 181 ms 12588 KB Ok
101 Correct 184 ms 12588 KB Ok
102 Correct 177 ms 12588 KB Ok
103 Correct 178 ms 12588 KB Ok
104 Correct 209 ms 12588 KB Ok
105 Correct 207 ms 12588 KB Ok
106 Correct 168 ms 12588 KB Ok
107 Correct 204 ms 12588 KB Ok
108 Correct 218 ms 12588 KB Ok
109 Correct 199 ms 12588 KB Ok
110 Correct 505 ms 40912 KB Ok
111 Correct 560 ms 41912 KB Ok
112 Correct 544 ms 41912 KB Ok
113 Correct 570 ms 41912 KB Ok
114 Correct 476 ms 41912 KB Ok
115 Correct 531 ms 42012 KB Ok
116 Correct 519 ms 42012 KB Ok
117 Correct 502 ms 42012 KB Ok
118 Correct 503 ms 42012 KB Ok
119 Correct 545 ms 42012 KB Ok
120 Correct 534 ms 42012 KB Ok
121 Correct 494 ms 42012 KB Ok
122 Correct 534 ms 42012 KB Ok
123 Correct 519 ms 42012 KB Ok
124 Correct 510 ms 42012 KB Ok
125 Correct 339 ms 42012 KB Ok