답안 #92362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92362 2019-01-02T15:47:45 Z Abelyan Nice sequence (IZhO18_sequence) C++17
100 / 100
392 ms 35192 KB
#include <bits/stdc++.h>
using namespace std;


#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORR(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTR(i,a,b) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define gcd __gcd
#define fr first
#define sc second
#define x real
#define y imag

typedef long long ll;
typedef long double ld;
const int N = 4e5+6;
const int K = 406;

int pref[N],timer=1;
int n,m,qan;

void dfs(int v){
	//cout<<v<<endl;
	if (v-n>=0 && !pref[v-n])dfs(v-n);
	if (v+m<=qan && !pref[v+m])dfs(v+m);
	pref[v]=timer++;
}

int main(){
	ios_base::sync_with_stdio(false);
	int t;
	cin>>t;
	//assert(t==3);
	while(t--){
		cin>>m>>n;
		//assert((m==3 && n==1) || (m==2 && n==3) || (m==1 && n==1));
		qan=n+m-1-gcd(n,m);
		cout<<qan<<endl;
		FORT(i,0,qan){
			if (!pref[i])dfs(i);
		}
		//FOR(i,qan+1)cout<<pref[i]<<" ";
		//cout<<endl;
		FORT(i,1,qan){
			cout<<pref[i]-pref[i-1]<<" ";
			pref[i-1]=0;
		}
		pref[qan]=0;
		timer=1;
		cout<<endl;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 380 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 380 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 3 ms 376 KB Ok
7 Correct 8 ms 888 KB Ok
8 Correct 4 ms 632 KB Ok
9 Correct 9 ms 888 KB Ok
10 Correct 6 ms 760 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 380 KB Ok
7 Correct 2 ms 372 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 380 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 58 ms 5368 KB Ok
7 Correct 48 ms 6264 KB Ok
8 Correct 93 ms 9336 KB Ok
9 Correct 71 ms 8184 KB Ok
10 Correct 40 ms 3576 KB Ok
11 Correct 65 ms 6136 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 380 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 376 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 2 ms 380 KB Ok
19 Correct 2 ms 372 KB Ok
20 Correct 2 ms 376 KB Ok
21 Correct 2 ms 376 KB Ok
22 Correct 2 ms 376 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 3 ms 376 KB Ok
25 Correct 3 ms 380 KB Ok
26 Correct 3 ms 376 KB Ok
27 Correct 3 ms 376 KB Ok
28 Correct 3 ms 376 KB Ok
29 Correct 3 ms 504 KB Ok
30 Correct 3 ms 376 KB Ok
31 Correct 3 ms 376 KB Ok
32 Correct 3 ms 376 KB Ok
33 Correct 3 ms 404 KB Ok
34 Correct 4 ms 504 KB Ok
35 Correct 4 ms 504 KB Ok
36 Correct 4 ms 504 KB Ok
37 Correct 4 ms 504 KB Ok
38 Correct 4 ms 504 KB Ok
39 Correct 4 ms 504 KB Ok
40 Correct 4 ms 504 KB Ok
41 Correct 4 ms 504 KB Ok
42 Correct 4 ms 504 KB Ok
43 Correct 4 ms 632 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 380 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 380 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 3 ms 376 KB Ok
19 Correct 8 ms 888 KB Ok
20 Correct 4 ms 632 KB Ok
21 Correct 9 ms 888 KB Ok
22 Correct 6 ms 760 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Correct 2 ms 376 KB Ok
27 Correct 2 ms 376 KB Ok
28 Correct 2 ms 380 KB Ok
29 Correct 2 ms 372 KB Ok
30 Correct 2 ms 376 KB Ok
31 Correct 2 ms 376 KB Ok
32 Correct 2 ms 376 KB Ok
33 Correct 2 ms 376 KB Ok
34 Correct 3 ms 376 KB Ok
35 Correct 3 ms 380 KB Ok
36 Correct 3 ms 376 KB Ok
37 Correct 3 ms 376 KB Ok
38 Correct 3 ms 376 KB Ok
39 Correct 3 ms 504 KB Ok
40 Correct 3 ms 376 KB Ok
41 Correct 3 ms 376 KB Ok
42 Correct 3 ms 376 KB Ok
43 Correct 3 ms 404 KB Ok
44 Correct 4 ms 504 KB Ok
45 Correct 4 ms 504 KB Ok
46 Correct 4 ms 504 KB Ok
47 Correct 4 ms 504 KB Ok
48 Correct 4 ms 504 KB Ok
49 Correct 4 ms 504 KB Ok
50 Correct 4 ms 504 KB Ok
51 Correct 4 ms 504 KB Ok
52 Correct 4 ms 504 KB Ok
53 Correct 4 ms 632 KB Ok
54 Correct 43 ms 2424 KB Ok
55 Correct 49 ms 2680 KB Ok
56 Correct 49 ms 2684 KB Ok
57 Correct 37 ms 2040 KB Ok
58 Correct 43 ms 2140 KB Ok
59 Correct 42 ms 2040 KB Ok
60 Correct 38 ms 1784 KB Ok
61 Correct 38 ms 2040 KB Ok
62 Correct 49 ms 2396 KB Ok
63 Correct 41 ms 2168 KB Ok
64 Correct 49 ms 2652 KB Ok
65 Correct 46 ms 2296 KB Ok
66 Correct 44 ms 2168 KB Ok
67 Correct 36 ms 2040 KB Ok
68 Correct 42 ms 2168 KB Ok
69 Correct 87 ms 8184 KB Ok
70 Correct 91 ms 8824 KB Ok
71 Correct 89 ms 8072 KB Ok
72 Correct 85 ms 8056 KB Ok
73 Correct 89 ms 7928 KB Ok
74 Correct 87 ms 7800 KB Ok
75 Correct 87 ms 7544 KB Ok
76 Correct 93 ms 8312 KB Ok
77 Correct 85 ms 7260 KB Ok
78 Correct 88 ms 7672 KB Ok
79 Correct 90 ms 8184 KB Ok
80 Correct 88 ms 8184 KB Ok
81 Correct 88 ms 7928 KB Ok
82 Correct 90 ms 8184 KB Ok
83 Correct 88 ms 7544 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 380 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 380 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 3 ms 376 KB Ok
19 Correct 8 ms 888 KB Ok
20 Correct 4 ms 632 KB Ok
21 Correct 9 ms 888 KB Ok
22 Correct 6 ms 760 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Correct 2 ms 376 KB Ok
27 Correct 2 ms 376 KB Ok
28 Correct 2 ms 380 KB Ok
29 Correct 2 ms 372 KB Ok
30 Correct 2 ms 376 KB Ok
31 Correct 2 ms 376 KB Ok
32 Correct 2 ms 376 KB Ok
33 Correct 2 ms 376 KB Ok
34 Correct 2 ms 380 KB Ok
35 Correct 2 ms 376 KB Ok
36 Correct 2 ms 376 KB Ok
37 Correct 2 ms 380 KB Ok
38 Correct 2 ms 376 KB Ok
39 Correct 58 ms 5368 KB Ok
40 Correct 48 ms 6264 KB Ok
41 Correct 93 ms 9336 KB Ok
42 Correct 71 ms 8184 KB Ok
43 Correct 40 ms 3576 KB Ok
44 Correct 65 ms 6136 KB Ok
45 Correct 3 ms 376 KB Ok
46 Correct 3 ms 380 KB Ok
47 Correct 3 ms 376 KB Ok
48 Correct 3 ms 376 KB Ok
49 Correct 3 ms 376 KB Ok
50 Correct 3 ms 504 KB Ok
51 Correct 3 ms 376 KB Ok
52 Correct 3 ms 376 KB Ok
53 Correct 3 ms 376 KB Ok
54 Correct 3 ms 404 KB Ok
55 Correct 4 ms 504 KB Ok
56 Correct 4 ms 504 KB Ok
57 Correct 4 ms 504 KB Ok
58 Correct 4 ms 504 KB Ok
59 Correct 4 ms 504 KB Ok
60 Correct 4 ms 504 KB Ok
61 Correct 4 ms 504 KB Ok
62 Correct 4 ms 504 KB Ok
63 Correct 4 ms 504 KB Ok
64 Correct 4 ms 632 KB Ok
65 Correct 43 ms 2424 KB Ok
66 Correct 49 ms 2680 KB Ok
67 Correct 49 ms 2684 KB Ok
68 Correct 37 ms 2040 KB Ok
69 Correct 43 ms 2140 KB Ok
70 Correct 42 ms 2040 KB Ok
71 Correct 38 ms 1784 KB Ok
72 Correct 38 ms 2040 KB Ok
73 Correct 49 ms 2396 KB Ok
74 Correct 41 ms 2168 KB Ok
75 Correct 49 ms 2652 KB Ok
76 Correct 46 ms 2296 KB Ok
77 Correct 44 ms 2168 KB Ok
78 Correct 36 ms 2040 KB Ok
79 Correct 42 ms 2168 KB Ok
80 Correct 87 ms 8184 KB Ok
81 Correct 91 ms 8824 KB Ok
82 Correct 89 ms 8072 KB Ok
83 Correct 85 ms 8056 KB Ok
84 Correct 89 ms 7928 KB Ok
85 Correct 87 ms 7800 KB Ok
86 Correct 87 ms 7544 KB Ok
87 Correct 93 ms 8312 KB Ok
88 Correct 85 ms 7260 KB Ok
89 Correct 88 ms 7672 KB Ok
90 Correct 90 ms 8184 KB Ok
91 Correct 88 ms 8184 KB Ok
92 Correct 88 ms 7928 KB Ok
93 Correct 90 ms 8184 KB Ok
94 Correct 88 ms 7544 KB Ok
95 Correct 108 ms 5504 KB Ok
96 Correct 150 ms 7332 KB Ok
97 Correct 147 ms 6576 KB Ok
98 Correct 112 ms 5544 KB Ok
99 Correct 135 ms 6008 KB Ok
100 Correct 135 ms 6220 KB Ok
101 Correct 137 ms 6392 KB Ok
102 Correct 132 ms 6236 KB Ok
103 Correct 133 ms 6392 KB Ok
104 Correct 156 ms 7560 KB Ok
105 Correct 147 ms 7080 KB Ok
106 Correct 128 ms 6776 KB Ok
107 Correct 143 ms 6936 KB Ok
108 Correct 155 ms 7488 KB Ok
109 Correct 143 ms 7288 KB Ok
110 Correct 369 ms 32284 KB Ok
111 Correct 391 ms 34552 KB Ok
112 Correct 381 ms 33144 KB Ok
113 Correct 378 ms 34436 KB Ok
114 Correct 376 ms 35192 KB Ok
115 Correct 384 ms 32960 KB Ok
116 Correct 390 ms 34924 KB Ok
117 Correct 378 ms 33656 KB Ok
118 Correct 383 ms 34004 KB Ok
119 Correct 374 ms 33400 KB Ok
120 Correct 381 ms 33328 KB Ok
121 Correct 366 ms 32340 KB Ok
122 Correct 377 ms 33868 KB Ok
123 Correct 392 ms 34808 KB Ok
124 Correct 366 ms 31080 KB Ok
125 Correct 254 ms 17912 KB Ok