답안 #89411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89411 2018-12-13T16:24:24 Z nicksona Nice sequence (IZhO18_sequence) C++14
100 / 100
918 ms 43868 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
int t;
int M=0;
int v[400001][3];
int mas[400001];
int fix[400001],nmas[1000001];

void top_sort (int u){
	fix[u]=1;
	for (int i=1;i<=2;i++){
		int node=v[u][i];
		if (fix[node]==0) top_sort(node);
	}
	mas[u]=++M;
}

void solve (int sz){
	
	for (int i=0;i<=sz;i++){
		if (i+n<=sz){
			v[i][2]=i+n;
			if(v[i][2]>v[i][1]) swap (v[i][2],v[i][1]);
		}
		if (i+m<=sz){
			v[i+m][2]=i;
			if(v[i+m][2]>v[i+m][1]) swap (v[i+m][2],v[i+m][1]);
		}
	}
	
	for (int i=0;i<=sz;i++){
		if (fix[i]==0){
			top_sort(i);
		}	
	}
	
	for (int i=0;i<=sz;i++){
 		nmas[i]=mas[i]-mas[i-1];
	}
	
	for (int i=0;i<=sz;i++){
		fix[i]=0;
		v[i][1]=0;
		v[i][2]=0;
	}
}

int gcd(int a,int b){
	if (a%b==0){
		return b;
	} 
	else{
		return gcd(b,a%b);
	}
}

main () {
	ios::sync_with_stdio(false);
	cin>>t;
	while (t--){
		cin>>n>>m;
		int ans=m+n-gcd(n,m)-1;
		M=0;
		solve(ans);
		cout<<ans<<endl;
		for (int i=1;i<=ans;i++){
			cout<<nmas[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}
/*	
  _   _   _          _
 | \ | | (_)        | |
 |  \| |  _    ___  | | __  ___    ___    _ __     __ _
 | . ` | | |  / __| | |/ / / __|  / _ \  | '_ \   / _` |
 | |\  | | | | (__  |   <  \__ \ | (_) | | | | | | (_| |
 |_| \_| |_|  \___| |_|\_\ |___/  \___/  |_| |_|  \__,_|
 
*/

Compilation message

sequence.cpp:60:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 440 KB Ok
3 Correct 2 ms 440 KB Ok
4 Correct 2 ms 468 KB Ok
5 Correct 2 ms 524 KB Ok
6 Correct 2 ms 616 KB Ok
7 Correct 2 ms 616 KB Ok
8 Correct 2 ms 616 KB Ok
9 Correct 2 ms 616 KB Ok
10 Correct 2 ms 628 KB Ok
11 Correct 2 ms 788 KB Ok
12 Correct 2 ms 788 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 812 KB Ok
2 Correct 2 ms 812 KB Ok
3 Correct 2 ms 812 KB Ok
4 Correct 2 ms 812 KB Ok
5 Correct 2 ms 812 KB Ok
6 Correct 4 ms 832 KB Ok
7 Correct 11 ms 1348 KB Ok
8 Correct 6 ms 1348 KB Ok
9 Correct 12 ms 1424 KB Ok
10 Correct 8 ms 1424 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1424 KB Ok
2 Correct 2 ms 1424 KB Ok
3 Correct 2 ms 1424 KB Ok
4 Correct 2 ms 1424 KB Ok
5 Correct 2 ms 1424 KB Ok
6 Correct 2 ms 1424 KB Ok
7 Correct 2 ms 1424 KB Ok
8 Correct 2 ms 1424 KB Ok
9 Correct 2 ms 1424 KB Ok
10 Correct 2 ms 1424 KB Ok
11 Correct 2 ms 1424 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1424 KB Ok
2 Correct 2 ms 1424 KB Ok
3 Correct 2 ms 1424 KB Ok
4 Correct 2 ms 1424 KB Ok
5 Correct 2 ms 1424 KB Ok
6 Correct 77 ms 9008 KB Ok
7 Correct 73 ms 10688 KB Ok
8 Correct 136 ms 13708 KB Ok
9 Correct 105 ms 13708 KB Ok
10 Correct 58 ms 13708 KB Ok
11 Correct 96 ms 13708 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 440 KB Ok
3 Correct 2 ms 440 KB Ok
4 Correct 2 ms 468 KB Ok
5 Correct 2 ms 524 KB Ok
6 Correct 2 ms 616 KB Ok
7 Correct 2 ms 616 KB Ok
8 Correct 2 ms 616 KB Ok
9 Correct 2 ms 616 KB Ok
10 Correct 2 ms 628 KB Ok
11 Correct 2 ms 788 KB Ok
12 Correct 2 ms 788 KB Ok
13 Correct 2 ms 1424 KB Ok
14 Correct 2 ms 1424 KB Ok
15 Correct 2 ms 1424 KB Ok
16 Correct 2 ms 1424 KB Ok
17 Correct 2 ms 1424 KB Ok
18 Correct 2 ms 1424 KB Ok
19 Correct 2 ms 1424 KB Ok
20 Correct 2 ms 1424 KB Ok
21 Correct 2 ms 1424 KB Ok
22 Correct 2 ms 1424 KB Ok
23 Correct 2 ms 1424 KB Ok
24 Correct 5 ms 13708 KB Ok
25 Correct 4 ms 13708 KB Ok
26 Correct 4 ms 13708 KB Ok
27 Correct 4 ms 13708 KB Ok
28 Correct 4 ms 13708 KB Ok
29 Correct 3 ms 13708 KB Ok
30 Correct 3 ms 13708 KB Ok
31 Correct 3 ms 13708 KB Ok
32 Correct 3 ms 13708 KB Ok
33 Correct 3 ms 13708 KB Ok
34 Correct 5 ms 13708 KB Ok
35 Correct 5 ms 13708 KB Ok
36 Correct 5 ms 13708 KB Ok
37 Correct 6 ms 13708 KB Ok
38 Correct 5 ms 13708 KB Ok
39 Correct 5 ms 13708 KB Ok
40 Correct 6 ms 13708 KB Ok
41 Correct 5 ms 13708 KB Ok
42 Correct 5 ms 13708 KB Ok
43 Correct 5 ms 13708 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 440 KB Ok
3 Correct 2 ms 440 KB Ok
4 Correct 2 ms 468 KB Ok
5 Correct 2 ms 524 KB Ok
6 Correct 2 ms 616 KB Ok
7 Correct 2 ms 616 KB Ok
8 Correct 2 ms 616 KB Ok
9 Correct 2 ms 616 KB Ok
10 Correct 2 ms 628 KB Ok
11 Correct 2 ms 788 KB Ok
12 Correct 2 ms 788 KB Ok
13 Correct 2 ms 812 KB Ok
14 Correct 2 ms 812 KB Ok
15 Correct 2 ms 812 KB Ok
16 Correct 2 ms 812 KB Ok
17 Correct 2 ms 812 KB Ok
18 Correct 4 ms 832 KB Ok
19 Correct 11 ms 1348 KB Ok
20 Correct 6 ms 1348 KB Ok
21 Correct 12 ms 1424 KB Ok
22 Correct 8 ms 1424 KB Ok
23 Correct 2 ms 1424 KB Ok
24 Correct 2 ms 1424 KB Ok
25 Correct 2 ms 1424 KB Ok
26 Correct 2 ms 1424 KB Ok
27 Correct 2 ms 1424 KB Ok
28 Correct 2 ms 1424 KB Ok
29 Correct 2 ms 1424 KB Ok
30 Correct 2 ms 1424 KB Ok
31 Correct 2 ms 1424 KB Ok
32 Correct 2 ms 1424 KB Ok
33 Correct 2 ms 1424 KB Ok
34 Correct 5 ms 13708 KB Ok
35 Correct 4 ms 13708 KB Ok
36 Correct 4 ms 13708 KB Ok
37 Correct 4 ms 13708 KB Ok
38 Correct 4 ms 13708 KB Ok
39 Correct 3 ms 13708 KB Ok
40 Correct 3 ms 13708 KB Ok
41 Correct 3 ms 13708 KB Ok
42 Correct 3 ms 13708 KB Ok
43 Correct 3 ms 13708 KB Ok
44 Correct 5 ms 13708 KB Ok
45 Correct 5 ms 13708 KB Ok
46 Correct 5 ms 13708 KB Ok
47 Correct 6 ms 13708 KB Ok
48 Correct 5 ms 13708 KB Ok
49 Correct 5 ms 13708 KB Ok
50 Correct 6 ms 13708 KB Ok
51 Correct 5 ms 13708 KB Ok
52 Correct 5 ms 13708 KB Ok
53 Correct 5 ms 13708 KB Ok
54 Correct 61 ms 13708 KB Ok
55 Correct 76 ms 13708 KB Ok
56 Correct 76 ms 13708 KB Ok
57 Correct 53 ms 13708 KB Ok
58 Correct 62 ms 13708 KB Ok
59 Correct 57 ms 13708 KB Ok
60 Correct 51 ms 13708 KB Ok
61 Correct 55 ms 13708 KB Ok
62 Correct 71 ms 13708 KB Ok
63 Correct 58 ms 13708 KB Ok
64 Correct 73 ms 13708 KB Ok
65 Correct 67 ms 13708 KB Ok
66 Correct 61 ms 13708 KB Ok
67 Correct 57 ms 13708 KB Ok
68 Correct 65 ms 13708 KB Ok
69 Correct 149 ms 13708 KB Ok
70 Correct 173 ms 13708 KB Ok
71 Correct 162 ms 13708 KB Ok
72 Correct 139 ms 13708 KB Ok
73 Correct 145 ms 13708 KB Ok
74 Correct 151 ms 13708 KB Ok
75 Correct 151 ms 13708 KB Ok
76 Correct 157 ms 13708 KB Ok
77 Correct 157 ms 13708 KB Ok
78 Correct 144 ms 13708 KB Ok
79 Correct 141 ms 13708 KB Ok
80 Correct 137 ms 13708 KB Ok
81 Correct 140 ms 13708 KB Ok
82 Correct 154 ms 13708 KB Ok
83 Correct 155 ms 13708 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 440 KB Ok
3 Correct 2 ms 440 KB Ok
4 Correct 2 ms 468 KB Ok
5 Correct 2 ms 524 KB Ok
6 Correct 2 ms 616 KB Ok
7 Correct 2 ms 616 KB Ok
8 Correct 2 ms 616 KB Ok
9 Correct 2 ms 616 KB Ok
10 Correct 2 ms 628 KB Ok
11 Correct 2 ms 788 KB Ok
12 Correct 2 ms 788 KB Ok
13 Correct 2 ms 812 KB Ok
14 Correct 2 ms 812 KB Ok
15 Correct 2 ms 812 KB Ok
16 Correct 2 ms 812 KB Ok
17 Correct 2 ms 812 KB Ok
18 Correct 4 ms 832 KB Ok
19 Correct 11 ms 1348 KB Ok
20 Correct 6 ms 1348 KB Ok
21 Correct 12 ms 1424 KB Ok
22 Correct 8 ms 1424 KB Ok
23 Correct 2 ms 1424 KB Ok
24 Correct 2 ms 1424 KB Ok
25 Correct 2 ms 1424 KB Ok
26 Correct 2 ms 1424 KB Ok
27 Correct 2 ms 1424 KB Ok
28 Correct 2 ms 1424 KB Ok
29 Correct 2 ms 1424 KB Ok
30 Correct 2 ms 1424 KB Ok
31 Correct 2 ms 1424 KB Ok
32 Correct 2 ms 1424 KB Ok
33 Correct 2 ms 1424 KB Ok
34 Correct 2 ms 1424 KB Ok
35 Correct 2 ms 1424 KB Ok
36 Correct 2 ms 1424 KB Ok
37 Correct 2 ms 1424 KB Ok
38 Correct 2 ms 1424 KB Ok
39 Correct 77 ms 9008 KB Ok
40 Correct 73 ms 10688 KB Ok
41 Correct 136 ms 13708 KB Ok
42 Correct 105 ms 13708 KB Ok
43 Correct 58 ms 13708 KB Ok
44 Correct 96 ms 13708 KB Ok
45 Correct 5 ms 13708 KB Ok
46 Correct 4 ms 13708 KB Ok
47 Correct 4 ms 13708 KB Ok
48 Correct 4 ms 13708 KB Ok
49 Correct 4 ms 13708 KB Ok
50 Correct 3 ms 13708 KB Ok
51 Correct 3 ms 13708 KB Ok
52 Correct 3 ms 13708 KB Ok
53 Correct 3 ms 13708 KB Ok
54 Correct 3 ms 13708 KB Ok
55 Correct 5 ms 13708 KB Ok
56 Correct 5 ms 13708 KB Ok
57 Correct 5 ms 13708 KB Ok
58 Correct 6 ms 13708 KB Ok
59 Correct 5 ms 13708 KB Ok
60 Correct 5 ms 13708 KB Ok
61 Correct 6 ms 13708 KB Ok
62 Correct 5 ms 13708 KB Ok
63 Correct 5 ms 13708 KB Ok
64 Correct 5 ms 13708 KB Ok
65 Correct 61 ms 13708 KB Ok
66 Correct 76 ms 13708 KB Ok
67 Correct 76 ms 13708 KB Ok
68 Correct 53 ms 13708 KB Ok
69 Correct 62 ms 13708 KB Ok
70 Correct 57 ms 13708 KB Ok
71 Correct 51 ms 13708 KB Ok
72 Correct 55 ms 13708 KB Ok
73 Correct 71 ms 13708 KB Ok
74 Correct 58 ms 13708 KB Ok
75 Correct 73 ms 13708 KB Ok
76 Correct 67 ms 13708 KB Ok
77 Correct 61 ms 13708 KB Ok
78 Correct 57 ms 13708 KB Ok
79 Correct 65 ms 13708 KB Ok
80 Correct 149 ms 13708 KB Ok
81 Correct 173 ms 13708 KB Ok
82 Correct 162 ms 13708 KB Ok
83 Correct 139 ms 13708 KB Ok
84 Correct 145 ms 13708 KB Ok
85 Correct 151 ms 13708 KB Ok
86 Correct 151 ms 13708 KB Ok
87 Correct 157 ms 13708 KB Ok
88 Correct 157 ms 13708 KB Ok
89 Correct 144 ms 13708 KB Ok
90 Correct 141 ms 13708 KB Ok
91 Correct 137 ms 13708 KB Ok
92 Correct 140 ms 13708 KB Ok
93 Correct 154 ms 13708 KB Ok
94 Correct 155 ms 13708 KB Ok
95 Correct 166 ms 13708 KB Ok
96 Correct 225 ms 14904 KB Ok
97 Correct 214 ms 14904 KB Ok
98 Correct 167 ms 14904 KB Ok
99 Correct 199 ms 14904 KB Ok
100 Correct 198 ms 14904 KB Ok
101 Correct 206 ms 14904 KB Ok
102 Correct 196 ms 14904 KB Ok
103 Correct 200 ms 14904 KB Ok
104 Correct 238 ms 14904 KB Ok
105 Correct 215 ms 14904 KB Ok
106 Correct 192 ms 14904 KB Ok
107 Correct 208 ms 14904 KB Ok
108 Correct 227 ms 14904 KB Ok
109 Correct 223 ms 15424 KB Ok
110 Correct 756 ms 40764 KB Ok
111 Correct 810 ms 43100 KB Ok
112 Correct 918 ms 43100 KB Ok
113 Correct 846 ms 43100 KB Ok
114 Correct 891 ms 43868 KB Ok
115 Correct 781 ms 43868 KB Ok
116 Correct 763 ms 43868 KB Ok
117 Correct 806 ms 43868 KB Ok
118 Correct 788 ms 43868 KB Ok
119 Correct 918 ms 43868 KB Ok
120 Correct 776 ms 43868 KB Ok
121 Correct 769 ms 43868 KB Ok
122 Correct 741 ms 43868 KB Ok
123 Correct 824 ms 43868 KB Ok
124 Correct 822 ms 43868 KB Ok
125 Correct 373 ms 43868 KB Ok