답안 #760593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760593 2023-06-17T23:19:06 Z NK_ Nice sequence (IZhO18_sequence) C++17
100 / 100
404 ms 31224 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())

using ll = long long;
template<class T> using V = vector<T>;

void solve() {
	int N, M; cin >> N >> M;

	// P[i] - P[i - M] > 0 => P[i] > P[i - M];
	// P[i - N] - P[i] > 0 => P[i] > P[i + N];

	int K = N + M - gcd(N, M);

	V<int> deg(K);
	for(int i = 0; i < K; i++) {
		for(auto v : V<int>{i - M, i + N}) {
			if (v < 0 || v >= K) continue;
			deg[v]++;
		}
	}

	queue<int> q; for(int i = 0; i < K; i++) {
		if (deg[i] == 0) q.push(i);
	}

	int cur = K;
	V<int> P(K);

	while(sz(q)) {
		int u = q.front(); q.pop();

		P[u] = cur--;

		for(auto v : V<int>{u - M, u + N}) {
			if (v < 0 || v >= K) continue;
			--deg[v];
			if (deg[v] == 0) q.push(v);
		}
	}

	cout << K - 1 << nl;
	for(int i = 1; i < K; i++) {
		cout << P[i] - P[i - 1] << " ";
	}
	cout << nl;
}	

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int T; cin >> T;
	while(T--) {
		solve();
	}

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 1 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 1 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 2 ms 340 KB Ok
7 Correct 7 ms 724 KB Ok
8 Correct 4 ms 540 KB Ok
9 Correct 10 ms 796 KB Ok
10 Correct 5 ms 596 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 1 ms 212 KB Ok
7 Correct 0 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 1 ms 212 KB Ok
10 Correct 0 ms 212 KB Ok
11 Correct 1 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 71 ms 4380 KB Ok
7 Correct 68 ms 3472 KB Ok
8 Correct 104 ms 6328 KB Ok
9 Correct 81 ms 6436 KB Ok
10 Correct 47 ms 2744 KB Ok
11 Correct 75 ms 5656 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 1 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 0 ms 212 KB Ok
16 Correct 1 ms 212 KB Ok
17 Correct 1 ms 212 KB Ok
18 Correct 1 ms 212 KB Ok
19 Correct 0 ms 212 KB Ok
20 Correct 0 ms 212 KB Ok
21 Correct 1 ms 212 KB Ok
22 Correct 0 ms 212 KB Ok
23 Correct 1 ms 212 KB Ok
24 Correct 2 ms 340 KB Ok
25 Correct 2 ms 340 KB Ok
26 Correct 2 ms 316 KB Ok
27 Correct 2 ms 340 KB Ok
28 Correct 2 ms 340 KB Ok
29 Correct 2 ms 324 KB Ok
30 Correct 2 ms 320 KB Ok
31 Correct 2 ms 340 KB Ok
32 Correct 2 ms 324 KB Ok
33 Correct 2 ms 340 KB Ok
34 Correct 3 ms 468 KB Ok
35 Correct 3 ms 468 KB Ok
36 Correct 3 ms 468 KB Ok
37 Correct 3 ms 448 KB Ok
38 Correct 3 ms 444 KB Ok
39 Correct 3 ms 496 KB Ok
40 Correct 5 ms 468 KB Ok
41 Correct 3 ms 444 KB Ok
42 Correct 4 ms 468 KB Ok
43 Correct 3 ms 468 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 1 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 1 ms 212 KB Ok
16 Correct 0 ms 212 KB Ok
17 Correct 1 ms 212 KB Ok
18 Correct 2 ms 340 KB Ok
19 Correct 7 ms 724 KB Ok
20 Correct 4 ms 540 KB Ok
21 Correct 10 ms 796 KB Ok
22 Correct 5 ms 596 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 0 ms 212 KB Ok
25 Correct 0 ms 212 KB Ok
26 Correct 1 ms 212 KB Ok
27 Correct 1 ms 212 KB Ok
28 Correct 1 ms 212 KB Ok
29 Correct 0 ms 212 KB Ok
30 Correct 0 ms 212 KB Ok
31 Correct 1 ms 212 KB Ok
32 Correct 0 ms 212 KB Ok
33 Correct 1 ms 212 KB Ok
34 Correct 2 ms 340 KB Ok
35 Correct 2 ms 340 KB Ok
36 Correct 2 ms 316 KB Ok
37 Correct 2 ms 340 KB Ok
38 Correct 2 ms 340 KB Ok
39 Correct 2 ms 324 KB Ok
40 Correct 2 ms 320 KB Ok
41 Correct 2 ms 340 KB Ok
42 Correct 2 ms 324 KB Ok
43 Correct 2 ms 340 KB Ok
44 Correct 3 ms 468 KB Ok
45 Correct 3 ms 468 KB Ok
46 Correct 3 ms 468 KB Ok
47 Correct 3 ms 448 KB Ok
48 Correct 3 ms 444 KB Ok
49 Correct 3 ms 496 KB Ok
50 Correct 5 ms 468 KB Ok
51 Correct 3 ms 444 KB Ok
52 Correct 4 ms 468 KB Ok
53 Correct 3 ms 468 KB Ok
54 Correct 55 ms 3260 KB Ok
55 Correct 62 ms 3216 KB Ok
56 Correct 57 ms 3260 KB Ok
57 Correct 44 ms 2552 KB Ok
58 Correct 53 ms 2956 KB Ok
59 Correct 52 ms 3048 KB Ok
60 Correct 46 ms 2864 KB Ok
61 Correct 57 ms 2844 KB Ok
62 Correct 61 ms 3156 KB Ok
63 Correct 49 ms 2900 KB Ok
64 Correct 57 ms 3352 KB Ok
65 Correct 54 ms 3164 KB Ok
66 Correct 52 ms 3200 KB Ok
67 Correct 45 ms 2736 KB Ok
68 Correct 52 ms 2848 KB Ok
69 Correct 106 ms 6580 KB Ok
70 Correct 87 ms 7564 KB Ok
71 Correct 91 ms 6100 KB Ok
72 Correct 95 ms 6808 KB Ok
73 Correct 83 ms 6408 KB Ok
74 Correct 89 ms 5616 KB Ok
75 Correct 83 ms 5660 KB Ok
76 Correct 83 ms 7208 KB Ok
77 Correct 82 ms 5424 KB Ok
78 Correct 85 ms 6984 KB Ok
79 Correct 108 ms 6704 KB Ok
80 Correct 88 ms 6436 KB Ok
81 Correct 84 ms 6860 KB Ok
82 Correct 83 ms 6564 KB Ok
83 Correct 83 ms 5696 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 1 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 1 ms 212 KB Ok
16 Correct 0 ms 212 KB Ok
17 Correct 1 ms 212 KB Ok
18 Correct 2 ms 340 KB Ok
19 Correct 7 ms 724 KB Ok
20 Correct 4 ms 540 KB Ok
21 Correct 10 ms 796 KB Ok
22 Correct 5 ms 596 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 0 ms 212 KB Ok
25 Correct 0 ms 212 KB Ok
26 Correct 1 ms 212 KB Ok
27 Correct 1 ms 212 KB Ok
28 Correct 1 ms 212 KB Ok
29 Correct 0 ms 212 KB Ok
30 Correct 0 ms 212 KB Ok
31 Correct 1 ms 212 KB Ok
32 Correct 0 ms 212 KB Ok
33 Correct 1 ms 212 KB Ok
34 Correct 0 ms 212 KB Ok
35 Correct 1 ms 212 KB Ok
36 Correct 0 ms 212 KB Ok
37 Correct 1 ms 212 KB Ok
38 Correct 0 ms 212 KB Ok
39 Correct 71 ms 4380 KB Ok
40 Correct 68 ms 3472 KB Ok
41 Correct 104 ms 6328 KB Ok
42 Correct 81 ms 6436 KB Ok
43 Correct 47 ms 2744 KB Ok
44 Correct 75 ms 5656 KB Ok
45 Correct 2 ms 340 KB Ok
46 Correct 2 ms 340 KB Ok
47 Correct 2 ms 316 KB Ok
48 Correct 2 ms 340 KB Ok
49 Correct 2 ms 340 KB Ok
50 Correct 2 ms 324 KB Ok
51 Correct 2 ms 320 KB Ok
52 Correct 2 ms 340 KB Ok
53 Correct 2 ms 324 KB Ok
54 Correct 2 ms 340 KB Ok
55 Correct 3 ms 468 KB Ok
56 Correct 3 ms 468 KB Ok
57 Correct 3 ms 468 KB Ok
58 Correct 3 ms 448 KB Ok
59 Correct 3 ms 444 KB Ok
60 Correct 3 ms 496 KB Ok
61 Correct 5 ms 468 KB Ok
62 Correct 3 ms 444 KB Ok
63 Correct 4 ms 468 KB Ok
64 Correct 3 ms 468 KB Ok
65 Correct 55 ms 3260 KB Ok
66 Correct 62 ms 3216 KB Ok
67 Correct 57 ms 3260 KB Ok
68 Correct 44 ms 2552 KB Ok
69 Correct 53 ms 2956 KB Ok
70 Correct 52 ms 3048 KB Ok
71 Correct 46 ms 2864 KB Ok
72 Correct 57 ms 2844 KB Ok
73 Correct 61 ms 3156 KB Ok
74 Correct 49 ms 2900 KB Ok
75 Correct 57 ms 3352 KB Ok
76 Correct 54 ms 3164 KB Ok
77 Correct 52 ms 3200 KB Ok
78 Correct 45 ms 2736 KB Ok
79 Correct 52 ms 2848 KB Ok
80 Correct 106 ms 6580 KB Ok
81 Correct 87 ms 7564 KB Ok
82 Correct 91 ms 6100 KB Ok
83 Correct 95 ms 6808 KB Ok
84 Correct 83 ms 6408 KB Ok
85 Correct 89 ms 5616 KB Ok
86 Correct 83 ms 5660 KB Ok
87 Correct 83 ms 7208 KB Ok
88 Correct 82 ms 5424 KB Ok
89 Correct 85 ms 6984 KB Ok
90 Correct 108 ms 6704 KB Ok
91 Correct 88 ms 6436 KB Ok
92 Correct 84 ms 6860 KB Ok
93 Correct 83 ms 6564 KB Ok
94 Correct 83 ms 5696 KB Ok
95 Correct 132 ms 8008 KB Ok
96 Correct 184 ms 11740 KB Ok
97 Correct 183 ms 10444 KB Ok
98 Correct 142 ms 8288 KB Ok
99 Correct 165 ms 9676 KB Ok
100 Correct 166 ms 9068 KB Ok
101 Correct 172 ms 10200 KB Ok
102 Correct 161 ms 10348 KB Ok
103 Correct 157 ms 9032 KB Ok
104 Correct 199 ms 10228 KB Ok
105 Correct 180 ms 10268 KB Ok
106 Correct 150 ms 8980 KB Ok
107 Correct 175 ms 9536 KB Ok
108 Correct 194 ms 10844 KB Ok
109 Correct 175 ms 10008 KB Ok
110 Correct 330 ms 23248 KB Ok
111 Correct 351 ms 31224 KB Ok
112 Correct 351 ms 25104 KB Ok
113 Correct 345 ms 28216 KB Ok
114 Correct 344 ms 29520 KB Ok
115 Correct 346 ms 28716 KB Ok
116 Correct 360 ms 28768 KB Ok
117 Correct 344 ms 29264 KB Ok
118 Correct 344 ms 25840 KB Ok
119 Correct 348 ms 30080 KB Ok
120 Correct 404 ms 25884 KB Ok
121 Correct 348 ms 24932 KB Ok
122 Correct 337 ms 27428 KB Ok
123 Correct 349 ms 31212 KB Ok
124 Correct 325 ms 22420 KB Ok
125 Correct 307 ms 13460 KB Ok