답안 #89393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89393 2018-12-13T08:02:00 Z nicksona Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 49492 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
int t;
vector <int> v[1000001];
bool OK=true;
int fix[1000001];
void go (int u,int col){
	fix[u]=col;
	for (int i=0;i<v[u].size();i++){
		int node=v[u][i];
		if (fix[node]==col){
			OK=false;
			return ;
		}
		if (OK&&fix[node]==0) go(node,col);
	}
}
bool check (int sz){
	
	for (int i=0;i<=sz;i++){
		if (i+n<=sz){
			v[i].pb(i+n);
		}
		if (i+m<=sz){
			v[i+m].pb(i);
		}
	}
	
	OK=true;
	for (int i=0;i<=sz;i++){
		if (fix[i]==0){
			go(i,i+1);
		}	
	}
	
	for (int i=0;i<=sz;i++){
		fix[i]=0;
		v[i].clear();
	}
	
	return OK;
}
int M=0;
int mas[1000001];

void top_sort (int u,int col){
	fix[u]=col;
	for (int i=0;i<v[u].size();i++){
		int node=v[u][i];
		if (fix[node]==0) top_sort(node,col);
	}
	mas[u]=++M;
}
int nmas[1000001];
void solve (int sz){
	
	for (int i=0;i<=sz;i++){
		if (i+n<=sz){
			v[i].pb(i+n);
		}
		if (i+m<=sz){
			v[i+m].pb(i);
		}
	}
	
	OK=true;
	for (int i=0;i<=sz;i++){
		if (fix[i]==0){
			top_sort(i,i+1);
		}	
	}
	
	
	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].clear();
	}
}
main () {
	ios::sync_with_stdio(false);
	cin>>t;
	while (t--){
		cin>>n>>m;
		int b=0,e=n+m,mid,ans=0;
		while (b<=e){
			mid= b + e >> 1;
			if (check(mid)){
				ans=mid;
				b=mid+1;
			}
			else{
				e=mid-1;
			}
		}
		M=0;
		if (ans>0) solve(ans);
		cout<<ans<<endl;
		for (int i=1;i<=ans;i++){
			cout<<nmas[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}
/*
1
2 4
  _   _   _          _
 | \ | | (_)        | |
 |  \| |  _    ___  | | __  ___    ___    _ __     __ _
 | . ` | | |  / __| | |/ / / __|  / _ \  | '_ \   / _` |
 | |\  | | | | (__  |   <  \__ \ | (_) | | | | | | (_| |
 |_| \_| |_|  \___| |_|\_\ |___/  \___/  |_| |_|  \__,_|

*/

Compilation message

sequence.cpp: In function 'void go(int, int)':
sequence.cpp:12:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<v[u].size();i++){
               ~^~~~~~~~~~~~
sequence.cpp: In function 'void top_sort(int, int)':
sequence.cpp:51:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<v[u].size();i++){
               ~^~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:86:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sequence.cpp: In function 'int main()':
sequence.cpp:93:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid= b + e >> 1;
         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23928 KB Ok
2 Correct 25 ms 23928 KB Ok
3 Correct 25 ms 23928 KB Ok
4 Correct 24 ms 24096 KB Ok
5 Correct 24 ms 24096 KB Ok
6 Correct 25 ms 24096 KB Ok
7 Correct 25 ms 24096 KB Ok
8 Correct 26 ms 24096 KB Ok
9 Correct 24 ms 24096 KB Ok
10 Correct 25 ms 24096 KB Ok
11 Correct 21 ms 24096 KB Ok
12 Correct 24 ms 24096 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 24096 KB Ok
2 Correct 23 ms 24096 KB Ok
3 Correct 23 ms 24096 KB Ok
4 Correct 24 ms 24188 KB Ok
5 Correct 24 ms 24188 KB Ok
6 Correct 31 ms 24252 KB Ok
7 Correct 57 ms 25088 KB Ok
8 Correct 37 ms 25088 KB Ok
9 Correct 57 ms 25440 KB Ok
10 Correct 46 ms 25440 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 25440 KB Ok
2 Correct 24 ms 25440 KB Ok
3 Correct 25 ms 25440 KB Ok
4 Correct 25 ms 25440 KB Ok
5 Correct 25 ms 25440 KB Ok
6 Correct 25 ms 25440 KB Ok
7 Correct 25 ms 25440 KB Ok
8 Correct 24 ms 25440 KB Ok
9 Correct 25 ms 25440 KB Ok
10 Correct 24 ms 25440 KB Ok
11 Correct 26 ms 25440 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 25440 KB Ok
2 Correct 25 ms 25440 KB Ok
3 Correct 21 ms 25440 KB Ok
4 Correct 24 ms 25440 KB Ok
5 Correct 21 ms 25440 KB Ok
6 Correct 398 ms 39516 KB Ok
7 Correct 417 ms 43984 KB Ok
8 Correct 782 ms 46600 KB Ok
9 Correct 487 ms 46600 KB Ok
10 Correct 280 ms 46600 KB Ok
11 Correct 472 ms 46600 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23928 KB Ok
2 Correct 25 ms 23928 KB Ok
3 Correct 25 ms 23928 KB Ok
4 Correct 24 ms 24096 KB Ok
5 Correct 24 ms 24096 KB Ok
6 Correct 25 ms 24096 KB Ok
7 Correct 25 ms 24096 KB Ok
8 Correct 26 ms 24096 KB Ok
9 Correct 24 ms 24096 KB Ok
10 Correct 25 ms 24096 KB Ok
11 Correct 21 ms 24096 KB Ok
12 Correct 24 ms 24096 KB Ok
13 Correct 24 ms 25440 KB Ok
14 Correct 24 ms 25440 KB Ok
15 Correct 25 ms 25440 KB Ok
16 Correct 25 ms 25440 KB Ok
17 Correct 25 ms 25440 KB Ok
18 Correct 25 ms 25440 KB Ok
19 Correct 25 ms 25440 KB Ok
20 Correct 24 ms 25440 KB Ok
21 Correct 25 ms 25440 KB Ok
22 Correct 24 ms 25440 KB Ok
23 Correct 26 ms 25440 KB Ok
24 Correct 30 ms 46600 KB Ok
25 Correct 29 ms 46600 KB Ok
26 Correct 29 ms 46600 KB Ok
27 Correct 29 ms 46600 KB Ok
28 Correct 28 ms 46600 KB Ok
29 Correct 28 ms 46600 KB Ok
30 Correct 27 ms 46600 KB Ok
31 Correct 28 ms 46600 KB Ok
32 Correct 30 ms 46600 KB Ok
33 Correct 28 ms 46600 KB Ok
34 Correct 37 ms 46600 KB Ok
35 Correct 33 ms 46600 KB Ok
36 Correct 37 ms 46600 KB Ok
37 Correct 37 ms 46600 KB Ok
38 Correct 36 ms 46600 KB Ok
39 Correct 36 ms 46600 KB Ok
40 Correct 37 ms 46600 KB Ok
41 Correct 36 ms 46600 KB Ok
42 Correct 38 ms 46600 KB Ok
43 Correct 37 ms 46600 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23928 KB Ok
2 Correct 25 ms 23928 KB Ok
3 Correct 25 ms 23928 KB Ok
4 Correct 24 ms 24096 KB Ok
5 Correct 24 ms 24096 KB Ok
6 Correct 25 ms 24096 KB Ok
7 Correct 25 ms 24096 KB Ok
8 Correct 26 ms 24096 KB Ok
9 Correct 24 ms 24096 KB Ok
10 Correct 25 ms 24096 KB Ok
11 Correct 21 ms 24096 KB Ok
12 Correct 24 ms 24096 KB Ok
13 Correct 24 ms 24096 KB Ok
14 Correct 23 ms 24096 KB Ok
15 Correct 23 ms 24096 KB Ok
16 Correct 24 ms 24188 KB Ok
17 Correct 24 ms 24188 KB Ok
18 Correct 31 ms 24252 KB Ok
19 Correct 57 ms 25088 KB Ok
20 Correct 37 ms 25088 KB Ok
21 Correct 57 ms 25440 KB Ok
22 Correct 46 ms 25440 KB Ok
23 Correct 24 ms 25440 KB Ok
24 Correct 24 ms 25440 KB Ok
25 Correct 25 ms 25440 KB Ok
26 Correct 25 ms 25440 KB Ok
27 Correct 25 ms 25440 KB Ok
28 Correct 25 ms 25440 KB Ok
29 Correct 25 ms 25440 KB Ok
30 Correct 24 ms 25440 KB Ok
31 Correct 25 ms 25440 KB Ok
32 Correct 24 ms 25440 KB Ok
33 Correct 26 ms 25440 KB Ok
34 Correct 30 ms 46600 KB Ok
35 Correct 29 ms 46600 KB Ok
36 Correct 29 ms 46600 KB Ok
37 Correct 29 ms 46600 KB Ok
38 Correct 28 ms 46600 KB Ok
39 Correct 28 ms 46600 KB Ok
40 Correct 27 ms 46600 KB Ok
41 Correct 28 ms 46600 KB Ok
42 Correct 30 ms 46600 KB Ok
43 Correct 28 ms 46600 KB Ok
44 Correct 37 ms 46600 KB Ok
45 Correct 33 ms 46600 KB Ok
46 Correct 37 ms 46600 KB Ok
47 Correct 37 ms 46600 KB Ok
48 Correct 36 ms 46600 KB Ok
49 Correct 36 ms 46600 KB Ok
50 Correct 37 ms 46600 KB Ok
51 Correct 36 ms 46600 KB Ok
52 Correct 38 ms 46600 KB Ok
53 Correct 37 ms 46600 KB Ok
54 Correct 346 ms 46600 KB Ok
55 Correct 364 ms 46600 KB Ok
56 Correct 438 ms 46600 KB Ok
57 Correct 228 ms 46600 KB Ok
58 Correct 272 ms 46600 KB Ok
59 Correct 251 ms 46600 KB Ok
60 Correct 225 ms 46600 KB Ok
61 Correct 248 ms 46600 KB Ok
62 Correct 324 ms 46600 KB Ok
63 Correct 279 ms 46600 KB Ok
64 Correct 370 ms 46600 KB Ok
65 Correct 310 ms 46600 KB Ok
66 Correct 261 ms 46600 KB Ok
67 Correct 268 ms 46600 KB Ok
68 Correct 292 ms 46600 KB Ok
69 Correct 1056 ms 46600 KB Ok
70 Correct 1309 ms 46600 KB Ok
71 Correct 1016 ms 46600 KB Ok
72 Correct 964 ms 46600 KB Ok
73 Correct 852 ms 46600 KB Ok
74 Correct 863 ms 46600 KB Ok
75 Correct 1072 ms 46600 KB Ok
76 Correct 1384 ms 46600 KB Ok
77 Correct 929 ms 46600 KB Ok
78 Correct 1423 ms 46600 KB Ok
79 Correct 1354 ms 46600 KB Ok
80 Correct 840 ms 46600 KB Ok
81 Correct 958 ms 46600 KB Ok
82 Correct 909 ms 46600 KB Ok
83 Correct 885 ms 46600 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23928 KB Ok
2 Correct 25 ms 23928 KB Ok
3 Correct 25 ms 23928 KB Ok
4 Correct 24 ms 24096 KB Ok
5 Correct 24 ms 24096 KB Ok
6 Correct 25 ms 24096 KB Ok
7 Correct 25 ms 24096 KB Ok
8 Correct 26 ms 24096 KB Ok
9 Correct 24 ms 24096 KB Ok
10 Correct 25 ms 24096 KB Ok
11 Correct 21 ms 24096 KB Ok
12 Correct 24 ms 24096 KB Ok
13 Correct 24 ms 24096 KB Ok
14 Correct 23 ms 24096 KB Ok
15 Correct 23 ms 24096 KB Ok
16 Correct 24 ms 24188 KB Ok
17 Correct 24 ms 24188 KB Ok
18 Correct 31 ms 24252 KB Ok
19 Correct 57 ms 25088 KB Ok
20 Correct 37 ms 25088 KB Ok
21 Correct 57 ms 25440 KB Ok
22 Correct 46 ms 25440 KB Ok
23 Correct 24 ms 25440 KB Ok
24 Correct 24 ms 25440 KB Ok
25 Correct 25 ms 25440 KB Ok
26 Correct 25 ms 25440 KB Ok
27 Correct 25 ms 25440 KB Ok
28 Correct 25 ms 25440 KB Ok
29 Correct 25 ms 25440 KB Ok
30 Correct 24 ms 25440 KB Ok
31 Correct 25 ms 25440 KB Ok
32 Correct 24 ms 25440 KB Ok
33 Correct 26 ms 25440 KB Ok
34 Correct 24 ms 25440 KB Ok
35 Correct 25 ms 25440 KB Ok
36 Correct 21 ms 25440 KB Ok
37 Correct 24 ms 25440 KB Ok
38 Correct 21 ms 25440 KB Ok
39 Correct 398 ms 39516 KB Ok
40 Correct 417 ms 43984 KB Ok
41 Correct 782 ms 46600 KB Ok
42 Correct 487 ms 46600 KB Ok
43 Correct 280 ms 46600 KB Ok
44 Correct 472 ms 46600 KB Ok
45 Correct 30 ms 46600 KB Ok
46 Correct 29 ms 46600 KB Ok
47 Correct 29 ms 46600 KB Ok
48 Correct 29 ms 46600 KB Ok
49 Correct 28 ms 46600 KB Ok
50 Correct 28 ms 46600 KB Ok
51 Correct 27 ms 46600 KB Ok
52 Correct 28 ms 46600 KB Ok
53 Correct 30 ms 46600 KB Ok
54 Correct 28 ms 46600 KB Ok
55 Correct 37 ms 46600 KB Ok
56 Correct 33 ms 46600 KB Ok
57 Correct 37 ms 46600 KB Ok
58 Correct 37 ms 46600 KB Ok
59 Correct 36 ms 46600 KB Ok
60 Correct 36 ms 46600 KB Ok
61 Correct 37 ms 46600 KB Ok
62 Correct 36 ms 46600 KB Ok
63 Correct 38 ms 46600 KB Ok
64 Correct 37 ms 46600 KB Ok
65 Correct 346 ms 46600 KB Ok
66 Correct 364 ms 46600 KB Ok
67 Correct 438 ms 46600 KB Ok
68 Correct 228 ms 46600 KB Ok
69 Correct 272 ms 46600 KB Ok
70 Correct 251 ms 46600 KB Ok
71 Correct 225 ms 46600 KB Ok
72 Correct 248 ms 46600 KB Ok
73 Correct 324 ms 46600 KB Ok
74 Correct 279 ms 46600 KB Ok
75 Correct 370 ms 46600 KB Ok
76 Correct 310 ms 46600 KB Ok
77 Correct 261 ms 46600 KB Ok
78 Correct 268 ms 46600 KB Ok
79 Correct 292 ms 46600 KB Ok
80 Correct 1056 ms 46600 KB Ok
81 Correct 1309 ms 46600 KB Ok
82 Correct 1016 ms 46600 KB Ok
83 Correct 964 ms 46600 KB Ok
84 Correct 852 ms 46600 KB Ok
85 Correct 863 ms 46600 KB Ok
86 Correct 1072 ms 46600 KB Ok
87 Correct 1384 ms 46600 KB Ok
88 Correct 929 ms 46600 KB Ok
89 Correct 1423 ms 46600 KB Ok
90 Correct 1354 ms 46600 KB Ok
91 Correct 840 ms 46600 KB Ok
92 Correct 958 ms 46600 KB Ok
93 Correct 909 ms 46600 KB Ok
94 Correct 885 ms 46600 KB Ok
95 Correct 1106 ms 46600 KB Ok
96 Correct 1746 ms 46600 KB Ok
97 Correct 1164 ms 46600 KB Ok
98 Correct 882 ms 46600 KB Ok
99 Correct 1022 ms 46600 KB Ok
100 Correct 1359 ms 46600 KB Ok
101 Correct 1286 ms 46600 KB Ok
102 Correct 1219 ms 46600 KB Ok
103 Correct 1042 ms 46600 KB Ok
104 Correct 1945 ms 46600 KB Ok
105 Correct 1381 ms 46600 KB Ok
106 Correct 1629 ms 46600 KB Ok
107 Correct 1579 ms 46600 KB Ok
108 Correct 1832 ms 46600 KB Ok
109 Correct 1668 ms 46600 KB Ok
110 Execution timed out 2039 ms 49492 KB Time limit exceeded
111 Halted 0 ms 0 KB -