답안 #344178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344178 2021-01-05T08:26:44 Z VEGAnn Nice sequence (IZhO18_sequence) C++14
100 / 100
516 ms 44644 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 400100;
vector<int> ts;
int n, m, len, mrk[N], pf[N];

void DFS(int v){
    mrk[v] = 1;

    if (v >= m){
        if (mrk[v - m] == 0)
            DFS(v - m);
    }

    if (v + n <= len){
        if (mrk[v + n] == 0)
            DFS(v + n);
    }

    ts.PB(v);
}


int main(){
#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#else
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL

    int qq; cin >> qq;

    for (; qq; qq--){
        cin >> n >> m;

      	int l = n + m - __gcd(n, m) - 1;

        cout << l << '\n';

        len = l;
        fill(mrk, mrk + len + 1, 0);
        fill(pf, pf + len + 1, -1);
        ts.clear();

        for (int i = 0; i <= len; i++)
            if (!mrk[i])
                DFS(i);

        int it = -len;

        for (int v : ts){
            int mx = it;
            it++;

            if (v >= m)
                mx = max(mx, pf[v - m]);

            if (v + n <= len)
                mx = max(mx, pf[v + n]);

            pf[v] = mx + 1;
        }

        for (int i = 1; i <= len; i++)
            cout << pf[i] - pf[i - 1] << " ";
        cout << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 2 ms 492 KB Ok
7 Correct 9 ms 1132 KB Ok
8 Correct 5 ms 620 KB Ok
9 Correct 11 ms 1132 KB Ok
10 Correct 7 ms 876 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 85 ms 7784 KB Ok
7 Correct 76 ms 11112 KB Ok
8 Correct 154 ms 14056 KB Ok
9 Correct 111 ms 12392 KB Ok
10 Correct 60 ms 5868 KB Ok
11 Correct 98 ms 9320 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 1 ms 364 KB Ok
19 Correct 1 ms 364 KB Ok
20 Correct 1 ms 364 KB Ok
21 Correct 1 ms 364 KB Ok
22 Correct 1 ms 364 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 2 ms 492 KB Ok
25 Correct 2 ms 492 KB Ok
26 Correct 2 ms 492 KB Ok
27 Correct 2 ms 492 KB Ok
28 Correct 2 ms 492 KB Ok
29 Correct 2 ms 364 KB Ok
30 Correct 2 ms 364 KB Ok
31 Correct 2 ms 492 KB Ok
32 Correct 3 ms 492 KB Ok
33 Correct 2 ms 492 KB Ok
34 Correct 4 ms 620 KB Ok
35 Correct 4 ms 620 KB Ok
36 Correct 4 ms 620 KB Ok
37 Correct 4 ms 620 KB Ok
38 Correct 4 ms 620 KB Ok
39 Correct 4 ms 620 KB Ok
40 Correct 4 ms 620 KB Ok
41 Correct 6 ms 620 KB Ok
42 Correct 4 ms 620 KB Ok
43 Correct 4 ms 620 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 2 ms 492 KB Ok
19 Correct 9 ms 1132 KB Ok
20 Correct 5 ms 620 KB Ok
21 Correct 11 ms 1132 KB Ok
22 Correct 7 ms 876 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 1 ms 364 KB Ok
25 Correct 1 ms 364 KB Ok
26 Correct 1 ms 364 KB Ok
27 Correct 1 ms 364 KB Ok
28 Correct 1 ms 364 KB Ok
29 Correct 1 ms 364 KB Ok
30 Correct 1 ms 364 KB Ok
31 Correct 1 ms 364 KB Ok
32 Correct 1 ms 364 KB Ok
33 Correct 1 ms 364 KB Ok
34 Correct 2 ms 492 KB Ok
35 Correct 2 ms 492 KB Ok
36 Correct 2 ms 492 KB Ok
37 Correct 2 ms 492 KB Ok
38 Correct 2 ms 492 KB Ok
39 Correct 2 ms 364 KB Ok
40 Correct 2 ms 364 KB Ok
41 Correct 2 ms 492 KB Ok
42 Correct 3 ms 492 KB Ok
43 Correct 2 ms 492 KB Ok
44 Correct 4 ms 620 KB Ok
45 Correct 4 ms 620 KB Ok
46 Correct 4 ms 620 KB Ok
47 Correct 4 ms 620 KB Ok
48 Correct 4 ms 620 KB Ok
49 Correct 4 ms 620 KB Ok
50 Correct 4 ms 620 KB Ok
51 Correct 6 ms 620 KB Ok
52 Correct 4 ms 620 KB Ok
53 Correct 4 ms 620 KB Ok
54 Correct 64 ms 3308 KB Ok
55 Correct 74 ms 3564 KB Ok
56 Correct 73 ms 3564 KB Ok
57 Correct 58 ms 2828 KB Ok
58 Correct 65 ms 3052 KB Ok
59 Correct 63 ms 2924 KB Ok
60 Correct 55 ms 2668 KB Ok
61 Correct 55 ms 2924 KB Ok
62 Correct 74 ms 3436 KB Ok
63 Correct 59 ms 2924 KB Ok
64 Correct 73 ms 3564 KB Ok
65 Correct 67 ms 3180 KB Ok
66 Correct 62 ms 3052 KB Ok
67 Correct 54 ms 2924 KB Ok
68 Correct 64 ms 3180 KB Ok
69 Correct 116 ms 10604 KB Ok
70 Correct 118 ms 11244 KB Ok
71 Correct 116 ms 10604 KB Ok
72 Correct 119 ms 10732 KB Ok
73 Correct 116 ms 10348 KB Ok
74 Correct 115 ms 9964 KB Ok
75 Correct 112 ms 9964 KB Ok
76 Correct 118 ms 10860 KB Ok
77 Correct 114 ms 9580 KB Ok
78 Correct 118 ms 9964 KB Ok
79 Correct 117 ms 10548 KB Ok
80 Correct 121 ms 10732 KB Ok
81 Correct 116 ms 10476 KB Ok
82 Correct 115 ms 10476 KB Ok
83 Correct 113 ms 9964 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 2 ms 492 KB Ok
19 Correct 9 ms 1132 KB Ok
20 Correct 5 ms 620 KB Ok
21 Correct 11 ms 1132 KB Ok
22 Correct 7 ms 876 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 1 ms 364 KB Ok
25 Correct 1 ms 364 KB Ok
26 Correct 1 ms 364 KB Ok
27 Correct 1 ms 364 KB Ok
28 Correct 1 ms 364 KB Ok
29 Correct 1 ms 364 KB Ok
30 Correct 1 ms 364 KB Ok
31 Correct 1 ms 364 KB Ok
32 Correct 1 ms 364 KB Ok
33 Correct 1 ms 364 KB Ok
34 Correct 1 ms 364 KB Ok
35 Correct 1 ms 364 KB Ok
36 Correct 1 ms 364 KB Ok
37 Correct 1 ms 364 KB Ok
38 Correct 1 ms 364 KB Ok
39 Correct 85 ms 7784 KB Ok
40 Correct 76 ms 11112 KB Ok
41 Correct 154 ms 14056 KB Ok
42 Correct 111 ms 12392 KB Ok
43 Correct 60 ms 5868 KB Ok
44 Correct 98 ms 9320 KB Ok
45 Correct 2 ms 492 KB Ok
46 Correct 2 ms 492 KB Ok
47 Correct 2 ms 492 KB Ok
48 Correct 2 ms 492 KB Ok
49 Correct 2 ms 492 KB Ok
50 Correct 2 ms 364 KB Ok
51 Correct 2 ms 364 KB Ok
52 Correct 2 ms 492 KB Ok
53 Correct 3 ms 492 KB Ok
54 Correct 2 ms 492 KB Ok
55 Correct 4 ms 620 KB Ok
56 Correct 4 ms 620 KB Ok
57 Correct 4 ms 620 KB Ok
58 Correct 4 ms 620 KB Ok
59 Correct 4 ms 620 KB Ok
60 Correct 4 ms 620 KB Ok
61 Correct 4 ms 620 KB Ok
62 Correct 6 ms 620 KB Ok
63 Correct 4 ms 620 KB Ok
64 Correct 4 ms 620 KB Ok
65 Correct 64 ms 3308 KB Ok
66 Correct 74 ms 3564 KB Ok
67 Correct 73 ms 3564 KB Ok
68 Correct 58 ms 2828 KB Ok
69 Correct 65 ms 3052 KB Ok
70 Correct 63 ms 2924 KB Ok
71 Correct 55 ms 2668 KB Ok
72 Correct 55 ms 2924 KB Ok
73 Correct 74 ms 3436 KB Ok
74 Correct 59 ms 2924 KB Ok
75 Correct 73 ms 3564 KB Ok
76 Correct 67 ms 3180 KB Ok
77 Correct 62 ms 3052 KB Ok
78 Correct 54 ms 2924 KB Ok
79 Correct 64 ms 3180 KB Ok
80 Correct 116 ms 10604 KB Ok
81 Correct 118 ms 11244 KB Ok
82 Correct 116 ms 10604 KB Ok
83 Correct 119 ms 10732 KB Ok
84 Correct 116 ms 10348 KB Ok
85 Correct 115 ms 9964 KB Ok
86 Correct 112 ms 9964 KB Ok
87 Correct 118 ms 10860 KB Ok
88 Correct 114 ms 9580 KB Ok
89 Correct 118 ms 9964 KB Ok
90 Correct 117 ms 10548 KB Ok
91 Correct 121 ms 10732 KB Ok
92 Correct 116 ms 10476 KB Ok
93 Correct 115 ms 10476 KB Ok
94 Correct 113 ms 9964 KB Ok
95 Correct 159 ms 7568 KB Ok
96 Correct 237 ms 10228 KB Ok
97 Correct 221 ms 9060 KB Ok
98 Correct 172 ms 8164 KB Ok
99 Correct 202 ms 8420 KB Ok
100 Correct 203 ms 8600 KB Ok
101 Correct 220 ms 9420 KB Ok
102 Correct 203 ms 8932 KB Ok
103 Correct 197 ms 9060 KB Ok
104 Correct 237 ms 10468 KB Ok
105 Correct 223 ms 10212 KB Ok
106 Correct 194 ms 9956 KB Ok
107 Correct 216 ms 9700 KB Ok
108 Correct 241 ms 10468 KB Ok
109 Correct 216 ms 10468 KB Ok
110 Correct 483 ms 41828 KB Ok
111 Correct 486 ms 44132 KB Ok
112 Correct 516 ms 41420 KB Ok
113 Correct 511 ms 44260 KB Ok
114 Correct 501 ms 44644 KB Ok
115 Correct 481 ms 42212 KB Ok
116 Correct 491 ms 44260 KB Ok
117 Correct 484 ms 43620 KB Ok
118 Correct 486 ms 43832 KB Ok
119 Correct 479 ms 42980 KB Ok
120 Correct 485 ms 42916 KB Ok
121 Correct 475 ms 42544 KB Ok
122 Correct 489 ms 42980 KB Ok
123 Correct 495 ms 44388 KB Ok
124 Correct 475 ms 39396 KB Ok
125 Correct 407 ms 27776 KB Ok