답안 #441074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441074 2021-07-04T05:36:05 Z 8e7 Nice sequence (IZhO18_sequence) C++14
100 / 100
459 ms 31428 KB
//Challenge: Accepted
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <utility>
#include <assert.h>
using namespace std;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
	while (l != r) {cout << *l << " ";l++;}
	cout << endl;
}
#define ll long long
#define ld long double
#define maxn 400005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int pref[maxn], deg[maxn];
bool vis[maxn];
int gcd(int a, int b) {
	if (a < b) swap(a, b);
	return b == 0 ? a : gcd(b, a % b);
}
int main() {
	io
	int t;
	cin >> t;
	while (t--) {
		int n, m, sw = 0;
		cin >> n >> m;
		if (n < m) swap(n, m), sw = 1;
		int siz = (m % n == 0 ? m : n + m - gcd(n, m));
		for (int i = 0;i < siz;i++) deg[i] = 0;
		int cnt = 0;
		queue<int> que;
		for (int i = 0;i < siz;i++) {
			if (i + n < siz) deg[i + n]++;
			if (i - m >= 0) deg[i - m]++;
		}
		for (int i = 0;i < siz;i++) {
			if (deg[i] == 0) que.push(i);
		}
		while (que.size()) {
			int cur = que.front();que.pop();
			pref[cur] = cnt++;
			if (cur + n < siz && --deg[cur + n] == 0) que.push(cur + n);
			if (cur - m >= 0 && --deg[cur - m] == 0) que.push(cur - m);
		}
		
		cout << siz - 1 << "\n";
		for (int i = 1;i < siz;i++) cout << (pref[i] - pref[i - 1]) * (sw ? 1: -1) << " ";
		cout << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Ok
2 Correct 1 ms 332 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 0 ms 332 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 0 ms 332 KB Ok
10 Correct 1 ms 384 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 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 10 ms 716 KB Ok
8 Correct 5 ms 460 KB Ok
9 Correct 11 ms 716 KB Ok
10 Correct 6 ms 584 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 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 0 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 0 ms 332 KB Ok
10 Correct 1 ms 332 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 0 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 83 ms 4408 KB Ok
7 Correct 68 ms 3912 KB Ok
8 Correct 176 ms 6040 KB Ok
9 Correct 107 ms 6308 KB Ok
10 Correct 59 ms 2756 KB Ok
11 Correct 96 ms 5316 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Ok
2 Correct 1 ms 332 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 0 ms 332 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 0 ms 332 KB Ok
10 Correct 1 ms 384 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Correct 0 ms 204 KB Ok
17 Correct 1 ms 204 KB Ok
18 Correct 1 ms 204 KB Ok
19 Correct 0 ms 204 KB Ok
20 Correct 1 ms 204 KB Ok
21 Correct 0 ms 332 KB Ok
22 Correct 1 ms 332 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 2 ms 332 KB Ok
25 Correct 2 ms 332 KB Ok
26 Correct 3 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 2 ms 332 KB Ok
31 Correct 2 ms 332 KB Ok
32 Correct 2 ms 332 KB Ok
33 Correct 2 ms 452 KB Ok
34 Correct 4 ms 460 KB Ok
35 Correct 4 ms 460 KB Ok
36 Correct 4 ms 460 KB Ok
37 Correct 4 ms 460 KB Ok
38 Correct 4 ms 512 KB Ok
39 Correct 4 ms 460 KB Ok
40 Correct 4 ms 460 KB Ok
41 Correct 4 ms 460 KB Ok
42 Correct 4 ms 460 KB Ok
43 Correct 4 ms 460 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Ok
2 Correct 1 ms 332 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 0 ms 332 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 0 ms 332 KB Ok
10 Correct 1 ms 384 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 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 10 ms 716 KB Ok
20 Correct 5 ms 460 KB Ok
21 Correct 11 ms 716 KB Ok
22 Correct 6 ms 584 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 0 ms 204 KB Ok
26 Correct 0 ms 204 KB Ok
27 Correct 1 ms 204 KB Ok
28 Correct 1 ms 204 KB Ok
29 Correct 0 ms 204 KB Ok
30 Correct 1 ms 204 KB Ok
31 Correct 0 ms 332 KB Ok
32 Correct 1 ms 332 KB Ok
33 Correct 0 ms 204 KB Ok
34 Correct 2 ms 332 KB Ok
35 Correct 2 ms 332 KB Ok
36 Correct 3 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 2 ms 332 KB Ok
41 Correct 2 ms 332 KB Ok
42 Correct 2 ms 332 KB Ok
43 Correct 2 ms 452 KB Ok
44 Correct 4 ms 460 KB Ok
45 Correct 4 ms 460 KB Ok
46 Correct 4 ms 460 KB Ok
47 Correct 4 ms 460 KB Ok
48 Correct 4 ms 512 KB Ok
49 Correct 4 ms 460 KB Ok
50 Correct 4 ms 460 KB Ok
51 Correct 4 ms 460 KB Ok
52 Correct 4 ms 460 KB Ok
53 Correct 4 ms 460 KB Ok
54 Correct 64 ms 2936 KB Ok
55 Correct 74 ms 3100 KB Ok
56 Correct 74 ms 3460 KB Ok
57 Correct 56 ms 2480 KB Ok
58 Correct 66 ms 2892 KB Ok
59 Correct 65 ms 2736 KB Ok
60 Correct 57 ms 2492 KB Ok
61 Correct 58 ms 2692 KB Ok
62 Correct 76 ms 2760 KB Ok
63 Correct 61 ms 2560 KB Ok
64 Correct 71 ms 2824 KB Ok
65 Correct 75 ms 3080 KB Ok
66 Correct 64 ms 2776 KB Ok
67 Correct 56 ms 2664 KB Ok
68 Correct 67 ms 2740 KB Ok
69 Correct 104 ms 6468 KB Ok
70 Correct 113 ms 7648 KB Ok
71 Correct 102 ms 5700 KB Ok
72 Correct 108 ms 6760 KB Ok
73 Correct 104 ms 6212 KB Ok
74 Correct 100 ms 5236 KB Ok
75 Correct 103 ms 5572 KB Ok
76 Correct 107 ms 7272 KB Ok
77 Correct 99 ms 4816 KB Ok
78 Correct 106 ms 7056 KB Ok
79 Correct 105 ms 6544 KB Ok
80 Correct 105 ms 6420 KB Ok
81 Correct 112 ms 6852 KB Ok
82 Correct 104 ms 6340 KB Ok
83 Correct 101 ms 5336 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Ok
2 Correct 1 ms 332 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 0 ms 332 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 0 ms 332 KB Ok
10 Correct 1 ms 384 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 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 10 ms 716 KB Ok
20 Correct 5 ms 460 KB Ok
21 Correct 11 ms 716 KB Ok
22 Correct 6 ms 584 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 0 ms 204 KB Ok
26 Correct 0 ms 204 KB Ok
27 Correct 1 ms 204 KB Ok
28 Correct 1 ms 204 KB Ok
29 Correct 0 ms 204 KB Ok
30 Correct 1 ms 204 KB Ok
31 Correct 0 ms 332 KB Ok
32 Correct 1 ms 332 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 0 ms 204 KB Ok
37 Correct 1 ms 204 KB Ok
38 Correct 1 ms 204 KB Ok
39 Correct 83 ms 4408 KB Ok
40 Correct 68 ms 3912 KB Ok
41 Correct 176 ms 6040 KB Ok
42 Correct 107 ms 6308 KB Ok
43 Correct 59 ms 2756 KB Ok
44 Correct 96 ms 5316 KB Ok
45 Correct 2 ms 332 KB Ok
46 Correct 2 ms 332 KB Ok
47 Correct 3 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 2 ms 332 KB Ok
52 Correct 2 ms 332 KB Ok
53 Correct 2 ms 332 KB Ok
54 Correct 2 ms 452 KB Ok
55 Correct 4 ms 460 KB Ok
56 Correct 4 ms 460 KB Ok
57 Correct 4 ms 460 KB Ok
58 Correct 4 ms 460 KB Ok
59 Correct 4 ms 512 KB Ok
60 Correct 4 ms 460 KB Ok
61 Correct 4 ms 460 KB Ok
62 Correct 4 ms 460 KB Ok
63 Correct 4 ms 460 KB Ok
64 Correct 4 ms 460 KB Ok
65 Correct 64 ms 2936 KB Ok
66 Correct 74 ms 3100 KB Ok
67 Correct 74 ms 3460 KB Ok
68 Correct 56 ms 2480 KB Ok
69 Correct 66 ms 2892 KB Ok
70 Correct 65 ms 2736 KB Ok
71 Correct 57 ms 2492 KB Ok
72 Correct 58 ms 2692 KB Ok
73 Correct 76 ms 2760 KB Ok
74 Correct 61 ms 2560 KB Ok
75 Correct 71 ms 2824 KB Ok
76 Correct 75 ms 3080 KB Ok
77 Correct 64 ms 2776 KB Ok
78 Correct 56 ms 2664 KB Ok
79 Correct 67 ms 2740 KB Ok
80 Correct 104 ms 6468 KB Ok
81 Correct 113 ms 7648 KB Ok
82 Correct 102 ms 5700 KB Ok
83 Correct 108 ms 6760 KB Ok
84 Correct 104 ms 6212 KB Ok
85 Correct 100 ms 5236 KB Ok
86 Correct 103 ms 5572 KB Ok
87 Correct 107 ms 7272 KB Ok
88 Correct 99 ms 4816 KB Ok
89 Correct 106 ms 7056 KB Ok
90 Correct 105 ms 6544 KB Ok
91 Correct 105 ms 6420 KB Ok
92 Correct 112 ms 6852 KB Ok
93 Correct 104 ms 6340 KB Ok
94 Correct 101 ms 5336 KB Ok
95 Correct 165 ms 7452 KB Ok
96 Correct 230 ms 10124 KB Ok
97 Correct 237 ms 8672 KB Ok
98 Correct 181 ms 8464 KB Ok
99 Correct 205 ms 8112 KB Ok
100 Correct 208 ms 7724 KB Ok
101 Correct 235 ms 8708 KB Ok
102 Correct 203 ms 8036 KB Ok
103 Correct 201 ms 8636 KB Ok
104 Correct 238 ms 9700 KB Ok
105 Correct 225 ms 9100 KB Ok
106 Correct 192 ms 9468 KB Ok
107 Correct 217 ms 8404 KB Ok
108 Correct 237 ms 8768 KB Ok
109 Correct 216 ms 9756 KB Ok
110 Correct 416 ms 22632 KB Ok
111 Correct 447 ms 31124 KB Ok
112 Correct 428 ms 24204 KB Ok
113 Correct 421 ms 27484 KB Ok
114 Correct 441 ms 29340 KB Ok
115 Correct 437 ms 28400 KB Ok
116 Correct 459 ms 28720 KB Ok
117 Correct 428 ms 28868 KB Ok
118 Correct 440 ms 24808 KB Ok
119 Correct 443 ms 29888 KB Ok
120 Correct 428 ms 24824 KB Ok
121 Correct 422 ms 24260 KB Ok
122 Correct 436 ms 26664 KB Ok
123 Correct 442 ms 31428 KB Ok
124 Correct 432 ms 22448 KB Ok
125 Correct 377 ms 13376 KB Ok