Submission #887410

# Submission time Handle Problem Language Result Execution time Memory
887410 2023-12-14T12:59:41 Z pcc Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 41136 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt")

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 4e5+10;
int n,m;
vector<int> paths[mxn];
int deg[mxn];
queue<int> q;
int arr[mxn];
map<pii,int> mp;

inline bool check(int tar){
	for(int i = 0;i+n<=tar;i++){
		paths[i+n].push_back(i);
		deg[i]++;
	}
	for(int i = 0;i+m<=tar;i++){
		paths[i].push_back(i+m);
		deg[i+m]++;
	}
	for(int i = 0;i<=tar;i++){
		if(!deg[i])q.push(i);
	}
	int p = 0;
	while(!q.empty()){
		auto now = q.front();
		arr[now] = ++p;
		q.pop();
		for(auto nxt:paths[now]){
			deg[nxt]--;
			if(!deg[nxt])q.push(nxt);
		}
	}
	for(int i = 0;i<=tar;i++){
		paths[i].clear();
		deg[i] = 0;
	}
	//cout<<tar<<":"<<p<<endl;
	return p == tar+1;
}

inline void solve(){
	cin>>n>>m;
	int l = 0,r = max(n,m)*2;
	if(mp.find({n,m}) != mp.end()){
		l = r = mp[make_pair(n,m)];
	}
	while(l != r){
		int mid = (l+r+1)>>1;
		if(check(mid))l = mid;
		else r = mid-1;
	}
	check(l);
	cout<<l<<'\n';
	//for(int i = 1;i<=l;i++)cout<<arr[i]<<' ';cout<<endl;
	mp[make_pair(n,m)] = l;
	for(int i  =1;i<=l;i++)cout<<arr[i]-arr[i-1]<<' ';cout<<'\n';
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;cin>>t;
	while(t--)solve();
}

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:67:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   67 |  for(int i  =1;i<=l;i++)cout<<arr[i]-arr[i-1]<<' ';cout<<'\n';
      |  ^~~
sequence.cpp:67:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   67 |  for(int i  =1;i<=l;i++)cout<<arr[i]-arr[i-1]<<' ';cout<<'\n';
      |                                                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 3 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 2 ms 12636 KB Ok
5 Correct 3 ms 12636 KB Ok
6 Correct 2 ms 12636 KB Ok
7 Correct 2 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 3 ms 12820 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 3 ms 12812 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Ok
2 Correct 3 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 4 ms 12984 KB Ok
5 Correct 3 ms 12636 KB Ok
6 Correct 5 ms 12892 KB Ok
7 Correct 15 ms 13404 KB Ok
8 Correct 8 ms 13148 KB Ok
9 Correct 16 ms 13660 KB Ok
10 Correct 10 ms 13256 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 2 ms 12636 KB Ok
5 Correct 3 ms 12820 KB Ok
6 Correct 2 ms 12636 KB Ok
7 Correct 2 ms 12636 KB Ok
8 Correct 3 ms 12636 KB Ok
9 Correct 2 ms 12636 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12820 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 3 ms 12636 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12632 KB Ok
6 Correct 155 ms 21028 KB Ok
7 Correct 151 ms 21380 KB Ok
8 Correct 267 ms 23228 KB Ok
9 Correct 190 ms 23164 KB Ok
10 Correct 118 ms 18208 KB Ok
11 Correct 193 ms 22760 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 3 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 2 ms 12636 KB Ok
5 Correct 3 ms 12636 KB Ok
6 Correct 2 ms 12636 KB Ok
7 Correct 2 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 3 ms 12820 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 3 ms 12812 KB Ok
13 Correct 3 ms 12632 KB Ok
14 Correct 2 ms 12636 KB Ok
15 Correct 2 ms 12636 KB Ok
16 Correct 2 ms 12636 KB Ok
17 Correct 3 ms 12820 KB Ok
18 Correct 2 ms 12636 KB Ok
19 Correct 2 ms 12636 KB Ok
20 Correct 3 ms 12636 KB Ok
21 Correct 2 ms 12636 KB Ok
22 Correct 2 ms 12636 KB Ok
23 Correct 2 ms 12636 KB Ok
24 Correct 5 ms 12892 KB Ok
25 Correct 5 ms 12892 KB Ok
26 Correct 5 ms 12936 KB Ok
27 Correct 4 ms 12892 KB Ok
28 Correct 4 ms 12932 KB Ok
29 Correct 4 ms 12888 KB Ok
30 Correct 4 ms 12892 KB Ok
31 Correct 5 ms 12892 KB Ok
32 Correct 5 ms 12892 KB Ok
33 Correct 4 ms 12892 KB Ok
34 Correct 7 ms 13072 KB Ok
35 Correct 7 ms 12892 KB Ok
36 Correct 7 ms 12892 KB Ok
37 Correct 7 ms 13072 KB Ok
38 Correct 7 ms 13312 KB Ok
39 Correct 7 ms 12892 KB Ok
40 Correct 7 ms 12888 KB Ok
41 Correct 7 ms 12892 KB Ok
42 Correct 7 ms 12892 KB Ok
43 Correct 8 ms 13060 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 3 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 2 ms 12636 KB Ok
5 Correct 3 ms 12636 KB Ok
6 Correct 2 ms 12636 KB Ok
7 Correct 2 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 3 ms 12820 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 3 ms 12812 KB Ok
13 Correct 3 ms 12632 KB Ok
14 Correct 3 ms 12636 KB Ok
15 Correct 2 ms 12636 KB Ok
16 Correct 4 ms 12984 KB Ok
17 Correct 3 ms 12636 KB Ok
18 Correct 5 ms 12892 KB Ok
19 Correct 15 ms 13404 KB Ok
20 Correct 8 ms 13148 KB Ok
21 Correct 16 ms 13660 KB Ok
22 Correct 10 ms 13256 KB Ok
23 Correct 3 ms 12632 KB Ok
24 Correct 2 ms 12636 KB Ok
25 Correct 2 ms 12636 KB Ok
26 Correct 2 ms 12636 KB Ok
27 Correct 3 ms 12820 KB Ok
28 Correct 2 ms 12636 KB Ok
29 Correct 2 ms 12636 KB Ok
30 Correct 3 ms 12636 KB Ok
31 Correct 2 ms 12636 KB Ok
32 Correct 2 ms 12636 KB Ok
33 Correct 2 ms 12636 KB Ok
34 Correct 5 ms 12892 KB Ok
35 Correct 5 ms 12892 KB Ok
36 Correct 5 ms 12936 KB Ok
37 Correct 4 ms 12892 KB Ok
38 Correct 4 ms 12932 KB Ok
39 Correct 4 ms 12888 KB Ok
40 Correct 4 ms 12892 KB Ok
41 Correct 5 ms 12892 KB Ok
42 Correct 5 ms 12892 KB Ok
43 Correct 4 ms 12892 KB Ok
44 Correct 7 ms 13072 KB Ok
45 Correct 7 ms 12892 KB Ok
46 Correct 7 ms 12892 KB Ok
47 Correct 7 ms 13072 KB Ok
48 Correct 7 ms 13312 KB Ok
49 Correct 7 ms 12892 KB Ok
50 Correct 7 ms 12888 KB Ok
51 Correct 7 ms 12892 KB Ok
52 Correct 7 ms 12892 KB Ok
53 Correct 8 ms 13060 KB Ok
54 Correct 105 ms 17324 KB Ok
55 Correct 123 ms 17412 KB Ok
56 Correct 120 ms 17620 KB Ok
57 Correct 92 ms 16900 KB Ok
58 Correct 110 ms 17376 KB Ok
59 Correct 106 ms 17096 KB Ok
60 Correct 90 ms 16956 KB Ok
61 Correct 92 ms 17168 KB Ok
62 Correct 129 ms 17488 KB Ok
63 Correct 98 ms 16972 KB Ok
64 Correct 123 ms 17376 KB Ok
65 Correct 119 ms 17856 KB Ok
66 Correct 104 ms 17148 KB Ok
67 Correct 87 ms 16900 KB Ok
68 Correct 122 ms 17588 KB Ok
69 Correct 220 ms 21420 KB Ok
70 Correct 239 ms 22800 KB Ok
71 Correct 221 ms 20792 KB Ok
72 Correct 232 ms 22100 KB Ok
73 Correct 213 ms 21332 KB Ok
74 Correct 197 ms 20308 KB Ok
75 Correct 209 ms 20428 KB Ok
76 Correct 259 ms 22728 KB Ok
77 Correct 195 ms 19848 KB Ok
78 Correct 237 ms 22352 KB Ok
79 Correct 215 ms 21572 KB Ok
80 Correct 229 ms 21340 KB Ok
81 Correct 232 ms 21992 KB Ok
82 Correct 228 ms 21460 KB Ok
83 Correct 202 ms 20332 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 3 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 2 ms 12636 KB Ok
5 Correct 3 ms 12636 KB Ok
6 Correct 2 ms 12636 KB Ok
7 Correct 2 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 3 ms 12820 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 3 ms 12812 KB Ok
13 Correct 3 ms 12632 KB Ok
14 Correct 3 ms 12636 KB Ok
15 Correct 2 ms 12636 KB Ok
16 Correct 4 ms 12984 KB Ok
17 Correct 3 ms 12636 KB Ok
18 Correct 5 ms 12892 KB Ok
19 Correct 15 ms 13404 KB Ok
20 Correct 8 ms 13148 KB Ok
21 Correct 16 ms 13660 KB Ok
22 Correct 10 ms 13256 KB Ok
23 Correct 3 ms 12632 KB Ok
24 Correct 2 ms 12636 KB Ok
25 Correct 2 ms 12636 KB Ok
26 Correct 2 ms 12636 KB Ok
27 Correct 3 ms 12820 KB Ok
28 Correct 2 ms 12636 KB Ok
29 Correct 2 ms 12636 KB Ok
30 Correct 3 ms 12636 KB Ok
31 Correct 2 ms 12636 KB Ok
32 Correct 2 ms 12636 KB Ok
33 Correct 2 ms 12636 KB Ok
34 Correct 2 ms 12820 KB Ok
35 Correct 2 ms 12636 KB Ok
36 Correct 3 ms 12636 KB Ok
37 Correct 3 ms 12636 KB Ok
38 Correct 2 ms 12632 KB Ok
39 Correct 155 ms 21028 KB Ok
40 Correct 151 ms 21380 KB Ok
41 Correct 267 ms 23228 KB Ok
42 Correct 190 ms 23164 KB Ok
43 Correct 118 ms 18208 KB Ok
44 Correct 193 ms 22760 KB Ok
45 Correct 5 ms 12892 KB Ok
46 Correct 5 ms 12892 KB Ok
47 Correct 5 ms 12936 KB Ok
48 Correct 4 ms 12892 KB Ok
49 Correct 4 ms 12932 KB Ok
50 Correct 4 ms 12888 KB Ok
51 Correct 4 ms 12892 KB Ok
52 Correct 5 ms 12892 KB Ok
53 Correct 5 ms 12892 KB Ok
54 Correct 4 ms 12892 KB Ok
55 Correct 7 ms 13072 KB Ok
56 Correct 7 ms 12892 KB Ok
57 Correct 7 ms 12892 KB Ok
58 Correct 7 ms 13072 KB Ok
59 Correct 7 ms 13312 KB Ok
60 Correct 7 ms 12892 KB Ok
61 Correct 7 ms 12888 KB Ok
62 Correct 7 ms 12892 KB Ok
63 Correct 7 ms 12892 KB Ok
64 Correct 8 ms 13060 KB Ok
65 Correct 105 ms 17324 KB Ok
66 Correct 123 ms 17412 KB Ok
67 Correct 120 ms 17620 KB Ok
68 Correct 92 ms 16900 KB Ok
69 Correct 110 ms 17376 KB Ok
70 Correct 106 ms 17096 KB Ok
71 Correct 90 ms 16956 KB Ok
72 Correct 92 ms 17168 KB Ok
73 Correct 129 ms 17488 KB Ok
74 Correct 98 ms 16972 KB Ok
75 Correct 123 ms 17376 KB Ok
76 Correct 119 ms 17856 KB Ok
77 Correct 104 ms 17148 KB Ok
78 Correct 87 ms 16900 KB Ok
79 Correct 122 ms 17588 KB Ok
80 Correct 220 ms 21420 KB Ok
81 Correct 239 ms 22800 KB Ok
82 Correct 221 ms 20792 KB Ok
83 Correct 232 ms 22100 KB Ok
84 Correct 213 ms 21332 KB Ok
85 Correct 197 ms 20308 KB Ok
86 Correct 209 ms 20428 KB Ok
87 Correct 259 ms 22728 KB Ok
88 Correct 195 ms 19848 KB Ok
89 Correct 237 ms 22352 KB Ok
90 Correct 215 ms 21572 KB Ok
91 Correct 229 ms 21340 KB Ok
92 Correct 232 ms 21992 KB Ok
93 Correct 228 ms 21460 KB Ok
94 Correct 202 ms 20332 KB Ok
95 Correct 273 ms 24676 KB Ok
96 Correct 451 ms 30280 KB Ok
97 Correct 434 ms 27368 KB Ok
98 Correct 303 ms 27872 KB Ok
99 Correct 392 ms 26552 KB Ok
100 Correct 405 ms 26912 KB Ok
101 Correct 405 ms 28644 KB Ok
102 Correct 376 ms 26952 KB Ok
103 Correct 386 ms 28464 KB Ok
104 Correct 484 ms 29660 KB Ok
105 Correct 465 ms 29116 KB Ok
106 Correct 347 ms 29144 KB Ok
107 Correct 409 ms 28344 KB Ok
108 Correct 471 ms 29400 KB Ok
109 Correct 396 ms 30176 KB Ok
110 Execution timed out 2045 ms 41136 KB Time limit exceeded
111 Halted 0 ms 0 KB -