Submission #89392

# Submission time Handle Problem Language Result Execution time Memory
89392 2018-12-13T08:00:16 Z nicksona Nice sequence (IZhO18_sequence) C++14
76 / 100
1410 ms 28688 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
int t;
vector <int> v[200001];
bool OK=true;
int fix[200001];
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;
         ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Ok
2 Correct 6 ms 5120 KB Ok
3 Correct 6 ms 5160 KB Ok
4 Correct 6 ms 5168 KB Ok
5 Correct 6 ms 5180 KB Ok
6 Correct 6 ms 5220 KB Ok
7 Correct 7 ms 5220 KB Ok
8 Correct 6 ms 5280 KB Ok
9 Correct 7 ms 5280 KB Ok
10 Correct 6 ms 5280 KB Ok
11 Correct 6 ms 5296 KB Ok
12 Correct 6 ms 5316 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5316 KB Ok
2 Correct 6 ms 5316 KB Ok
3 Correct 6 ms 5316 KB Ok
4 Correct 7 ms 5316 KB Ok
5 Correct 6 ms 5316 KB Ok
6 Correct 10 ms 5500 KB Ok
7 Correct 39 ms 6396 KB Ok
8 Correct 19 ms 6396 KB Ok
9 Correct 44 ms 6592 KB Ok
10 Correct 25 ms 6592 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6592 KB Ok
2 Correct 5 ms 6592 KB Ok
3 Correct 5 ms 6592 KB Ok
4 Correct 5 ms 6592 KB Ok
5 Correct 6 ms 6592 KB Ok
6 Correct 6 ms 6592 KB Ok
7 Correct 5 ms 6592 KB Ok
8 Correct 6 ms 6592 KB Ok
9 Correct 7 ms 6592 KB Ok
10 Correct 7 ms 6592 KB Ok
11 Correct 7 ms 6592 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6592 KB Ok
2 Correct 6 ms 6592 KB Ok
3 Correct 6 ms 6592 KB Ok
4 Correct 6 ms 6592 KB Ok
5 Correct 6 ms 6592 KB Ok
6 Correct 414 ms 20696 KB Ok
7 Correct 384 ms 25324 KB Ok
8 Correct 785 ms 28020 KB Ok
9 Correct 497 ms 28020 KB Ok
10 Correct 258 ms 28020 KB Ok
11 Correct 435 ms 28020 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Ok
2 Correct 6 ms 5120 KB Ok
3 Correct 6 ms 5160 KB Ok
4 Correct 6 ms 5168 KB Ok
5 Correct 6 ms 5180 KB Ok
6 Correct 6 ms 5220 KB Ok
7 Correct 7 ms 5220 KB Ok
8 Correct 6 ms 5280 KB Ok
9 Correct 7 ms 5280 KB Ok
10 Correct 6 ms 5280 KB Ok
11 Correct 6 ms 5296 KB Ok
12 Correct 6 ms 5316 KB Ok
13 Correct 5 ms 6592 KB Ok
14 Correct 5 ms 6592 KB Ok
15 Correct 5 ms 6592 KB Ok
16 Correct 5 ms 6592 KB Ok
17 Correct 6 ms 6592 KB Ok
18 Correct 6 ms 6592 KB Ok
19 Correct 5 ms 6592 KB Ok
20 Correct 6 ms 6592 KB Ok
21 Correct 7 ms 6592 KB Ok
22 Correct 7 ms 6592 KB Ok
23 Correct 7 ms 6592 KB Ok
24 Correct 10 ms 28020 KB Ok
25 Correct 10 ms 28020 KB Ok
26 Correct 11 ms 28020 KB Ok
27 Correct 11 ms 28020 KB Ok
28 Correct 10 ms 28020 KB Ok
29 Correct 10 ms 28020 KB Ok
30 Correct 9 ms 28020 KB Ok
31 Correct 11 ms 28020 KB Ok
32 Correct 11 ms 28020 KB Ok
33 Correct 10 ms 28020 KB Ok
34 Correct 19 ms 28020 KB Ok
35 Correct 19 ms 28020 KB Ok
36 Correct 19 ms 28020 KB Ok
37 Correct 20 ms 28020 KB Ok
38 Correct 19 ms 28020 KB Ok
39 Correct 18 ms 28020 KB Ok
40 Correct 20 ms 28020 KB Ok
41 Correct 18 ms 28020 KB Ok
42 Correct 18 ms 28020 KB Ok
43 Correct 19 ms 28020 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Ok
2 Correct 6 ms 5120 KB Ok
3 Correct 6 ms 5160 KB Ok
4 Correct 6 ms 5168 KB Ok
5 Correct 6 ms 5180 KB Ok
6 Correct 6 ms 5220 KB Ok
7 Correct 7 ms 5220 KB Ok
8 Correct 6 ms 5280 KB Ok
9 Correct 7 ms 5280 KB Ok
10 Correct 6 ms 5280 KB Ok
11 Correct 6 ms 5296 KB Ok
12 Correct 6 ms 5316 KB Ok
13 Correct 6 ms 5316 KB Ok
14 Correct 6 ms 5316 KB Ok
15 Correct 6 ms 5316 KB Ok
16 Correct 7 ms 5316 KB Ok
17 Correct 6 ms 5316 KB Ok
18 Correct 10 ms 5500 KB Ok
19 Correct 39 ms 6396 KB Ok
20 Correct 19 ms 6396 KB Ok
21 Correct 44 ms 6592 KB Ok
22 Correct 25 ms 6592 KB Ok
23 Correct 5 ms 6592 KB Ok
24 Correct 5 ms 6592 KB Ok
25 Correct 5 ms 6592 KB Ok
26 Correct 5 ms 6592 KB Ok
27 Correct 6 ms 6592 KB Ok
28 Correct 6 ms 6592 KB Ok
29 Correct 5 ms 6592 KB Ok
30 Correct 6 ms 6592 KB Ok
31 Correct 7 ms 6592 KB Ok
32 Correct 7 ms 6592 KB Ok
33 Correct 7 ms 6592 KB Ok
34 Correct 10 ms 28020 KB Ok
35 Correct 10 ms 28020 KB Ok
36 Correct 11 ms 28020 KB Ok
37 Correct 11 ms 28020 KB Ok
38 Correct 10 ms 28020 KB Ok
39 Correct 10 ms 28020 KB Ok
40 Correct 9 ms 28020 KB Ok
41 Correct 11 ms 28020 KB Ok
42 Correct 11 ms 28020 KB Ok
43 Correct 10 ms 28020 KB Ok
44 Correct 19 ms 28020 KB Ok
45 Correct 19 ms 28020 KB Ok
46 Correct 19 ms 28020 KB Ok
47 Correct 20 ms 28020 KB Ok
48 Correct 19 ms 28020 KB Ok
49 Correct 18 ms 28020 KB Ok
50 Correct 20 ms 28020 KB Ok
51 Correct 18 ms 28020 KB Ok
52 Correct 18 ms 28020 KB Ok
53 Correct 19 ms 28020 KB Ok
54 Correct 303 ms 28020 KB Ok
55 Correct 347 ms 28020 KB Ok
56 Correct 376 ms 28020 KB Ok
57 Correct 239 ms 28020 KB Ok
58 Correct 282 ms 28020 KB Ok
59 Correct 235 ms 28020 KB Ok
60 Correct 209 ms 28020 KB Ok
61 Correct 237 ms 28020 KB Ok
62 Correct 320 ms 28020 KB Ok
63 Correct 263 ms 28020 KB Ok
64 Correct 353 ms 28020 KB Ok
65 Correct 280 ms 28020 KB Ok
66 Correct 247 ms 28020 KB Ok
67 Correct 227 ms 28020 KB Ok
68 Correct 266 ms 28020 KB Ok
69 Correct 977 ms 28020 KB Ok
70 Correct 1055 ms 28020 KB Ok
71 Correct 937 ms 28020 KB Ok
72 Correct 871 ms 28020 KB Ok
73 Correct 1410 ms 28020 KB Ok
74 Correct 989 ms 28020 KB Ok
75 Correct 1187 ms 28020 KB Ok
76 Correct 1230 ms 28020 KB Ok
77 Correct 805 ms 28020 KB Ok
78 Correct 1014 ms 28020 KB Ok
79 Correct 1043 ms 28020 KB Ok
80 Correct 1012 ms 28020 KB Ok
81 Correct 1245 ms 28020 KB Ok
82 Correct 932 ms 28020 KB Ok
83 Correct 946 ms 28020 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Ok
2 Correct 6 ms 5120 KB Ok
3 Correct 6 ms 5160 KB Ok
4 Correct 6 ms 5168 KB Ok
5 Correct 6 ms 5180 KB Ok
6 Correct 6 ms 5220 KB Ok
7 Correct 7 ms 5220 KB Ok
8 Correct 6 ms 5280 KB Ok
9 Correct 7 ms 5280 KB Ok
10 Correct 6 ms 5280 KB Ok
11 Correct 6 ms 5296 KB Ok
12 Correct 6 ms 5316 KB Ok
13 Correct 6 ms 5316 KB Ok
14 Correct 6 ms 5316 KB Ok
15 Correct 6 ms 5316 KB Ok
16 Correct 7 ms 5316 KB Ok
17 Correct 6 ms 5316 KB Ok
18 Correct 10 ms 5500 KB Ok
19 Correct 39 ms 6396 KB Ok
20 Correct 19 ms 6396 KB Ok
21 Correct 44 ms 6592 KB Ok
22 Correct 25 ms 6592 KB Ok
23 Correct 5 ms 6592 KB Ok
24 Correct 5 ms 6592 KB Ok
25 Correct 5 ms 6592 KB Ok
26 Correct 5 ms 6592 KB Ok
27 Correct 6 ms 6592 KB Ok
28 Correct 6 ms 6592 KB Ok
29 Correct 5 ms 6592 KB Ok
30 Correct 6 ms 6592 KB Ok
31 Correct 7 ms 6592 KB Ok
32 Correct 7 ms 6592 KB Ok
33 Correct 7 ms 6592 KB Ok
34 Correct 6 ms 6592 KB Ok
35 Correct 6 ms 6592 KB Ok
36 Correct 6 ms 6592 KB Ok
37 Correct 6 ms 6592 KB Ok
38 Correct 6 ms 6592 KB Ok
39 Correct 414 ms 20696 KB Ok
40 Correct 384 ms 25324 KB Ok
41 Correct 785 ms 28020 KB Ok
42 Correct 497 ms 28020 KB Ok
43 Correct 258 ms 28020 KB Ok
44 Correct 435 ms 28020 KB Ok
45 Correct 10 ms 28020 KB Ok
46 Correct 10 ms 28020 KB Ok
47 Correct 11 ms 28020 KB Ok
48 Correct 11 ms 28020 KB Ok
49 Correct 10 ms 28020 KB Ok
50 Correct 10 ms 28020 KB Ok
51 Correct 9 ms 28020 KB Ok
52 Correct 11 ms 28020 KB Ok
53 Correct 11 ms 28020 KB Ok
54 Correct 10 ms 28020 KB Ok
55 Correct 19 ms 28020 KB Ok
56 Correct 19 ms 28020 KB Ok
57 Correct 19 ms 28020 KB Ok
58 Correct 20 ms 28020 KB Ok
59 Correct 19 ms 28020 KB Ok
60 Correct 18 ms 28020 KB Ok
61 Correct 20 ms 28020 KB Ok
62 Correct 18 ms 28020 KB Ok
63 Correct 18 ms 28020 KB Ok
64 Correct 19 ms 28020 KB Ok
65 Correct 303 ms 28020 KB Ok
66 Correct 347 ms 28020 KB Ok
67 Correct 376 ms 28020 KB Ok
68 Correct 239 ms 28020 KB Ok
69 Correct 282 ms 28020 KB Ok
70 Correct 235 ms 28020 KB Ok
71 Correct 209 ms 28020 KB Ok
72 Correct 237 ms 28020 KB Ok
73 Correct 320 ms 28020 KB Ok
74 Correct 263 ms 28020 KB Ok
75 Correct 353 ms 28020 KB Ok
76 Correct 280 ms 28020 KB Ok
77 Correct 247 ms 28020 KB Ok
78 Correct 227 ms 28020 KB Ok
79 Correct 266 ms 28020 KB Ok
80 Correct 977 ms 28020 KB Ok
81 Correct 1055 ms 28020 KB Ok
82 Correct 937 ms 28020 KB Ok
83 Correct 871 ms 28020 KB Ok
84 Correct 1410 ms 28020 KB Ok
85 Correct 989 ms 28020 KB Ok
86 Correct 1187 ms 28020 KB Ok
87 Correct 1230 ms 28020 KB Ok
88 Correct 805 ms 28020 KB Ok
89 Correct 1014 ms 28020 KB Ok
90 Correct 1043 ms 28020 KB Ok
91 Correct 1012 ms 28020 KB Ok
92 Correct 1245 ms 28020 KB Ok
93 Correct 932 ms 28020 KB Ok
94 Correct 946 ms 28020 KB Ok
95 Runtime error 323 ms 28688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
96 Halted 0 ms 0 KB -