Submission #887417

# Submission time Handle Problem Language Result Execution time Memory
887417 2023-12-14T13:38:55 Z pcc Nice sequence (IZhO18_sequence) C++14
100 / 100
1085 ms 53324 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,r;
	l = r = n+m-__gcd(n,m)-1;
	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:65:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   65 |  for(int i  =1;i<=l;i++)cout<<arr[i]-arr[i-1]<<' ';cout<<'\n';
      |  ^~~
sequence.cpp:65:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   65 |  for(int i  =1;i<=l;i++)cout<<arr[i]-arr[i-1]<<' ';cout<<'\n';
      |                                                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 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 12632 KB Ok
6 Correct 2 ms 12632 KB Ok
7 Correct 4 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 2 ms 12632 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 2 ms 12636 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 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 12636 KB Ok
6 Correct 5 ms 12892 KB Ok
7 Correct 8 ms 13404 KB Ok
8 Correct 7 ms 12892 KB Ok
9 Correct 11 ms 13404 KB Ok
10 Correct 6 ms 13148 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 2 ms 12632 KB Ok
5 Correct 2 ms 12636 KB Ok
6 Correct 4 ms 12644 KB Ok
7 Correct 3 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 2 ms 12636 KB Ok
10 Correct 2 ms 12732 KB Ok
11 Correct 2 ms 12724 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 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 12636 KB Ok
6 Correct 54 ms 20740 KB Ok
7 Correct 49 ms 21100 KB Ok
8 Correct 85 ms 23224 KB Ok
9 Correct 69 ms 22680 KB Ok
10 Correct 42 ms 18004 KB Ok
11 Correct 81 ms 22552 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 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 12632 KB Ok
6 Correct 2 ms 12632 KB Ok
7 Correct 4 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 2 ms 12632 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 2 ms 12636 KB Ok
13 Correct 3 ms 12636 KB Ok
14 Correct 2 ms 12636 KB Ok
15 Correct 2 ms 12636 KB Ok
16 Correct 2 ms 12632 KB Ok
17 Correct 2 ms 12636 KB Ok
18 Correct 4 ms 12644 KB Ok
19 Correct 3 ms 12636 KB Ok
20 Correct 2 ms 12636 KB Ok
21 Correct 2 ms 12636 KB Ok
22 Correct 2 ms 12732 KB Ok
23 Correct 2 ms 12724 KB Ok
24 Correct 4 ms 12892 KB Ok
25 Correct 3 ms 12892 KB Ok
26 Correct 4 ms 12888 KB Ok
27 Correct 3 ms 12892 KB Ok
28 Correct 3 ms 12732 KB Ok
29 Correct 3 ms 12892 KB Ok
30 Correct 3 ms 12892 KB Ok
31 Correct 4 ms 12892 KB Ok
32 Correct 4 ms 12892 KB Ok
33 Correct 3 ms 12892 KB Ok
34 Correct 5 ms 12892 KB Ok
35 Correct 4 ms 12984 KB Ok
36 Correct 5 ms 13060 KB Ok
37 Correct 6 ms 12892 KB Ok
38 Correct 5 ms 13144 KB Ok
39 Correct 5 ms 12888 KB Ok
40 Correct 5 ms 12892 KB Ok
41 Correct 5 ms 13148 KB Ok
42 Correct 5 ms 12888 KB Ok
43 Correct 5 ms 12892 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 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 12632 KB Ok
6 Correct 2 ms 12632 KB Ok
7 Correct 4 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 2 ms 12632 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 2 ms 12636 KB Ok
13 Correct 3 ms 12636 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 12636 KB Ok
18 Correct 5 ms 12892 KB Ok
19 Correct 8 ms 13404 KB Ok
20 Correct 7 ms 12892 KB Ok
21 Correct 11 ms 13404 KB Ok
22 Correct 6 ms 13148 KB Ok
23 Correct 3 ms 12636 KB Ok
24 Correct 2 ms 12636 KB Ok
25 Correct 2 ms 12636 KB Ok
26 Correct 2 ms 12632 KB Ok
27 Correct 2 ms 12636 KB Ok
28 Correct 4 ms 12644 KB Ok
29 Correct 3 ms 12636 KB Ok
30 Correct 2 ms 12636 KB Ok
31 Correct 2 ms 12636 KB Ok
32 Correct 2 ms 12732 KB Ok
33 Correct 2 ms 12724 KB Ok
34 Correct 4 ms 12892 KB Ok
35 Correct 3 ms 12892 KB Ok
36 Correct 4 ms 12888 KB Ok
37 Correct 3 ms 12892 KB Ok
38 Correct 3 ms 12732 KB Ok
39 Correct 3 ms 12892 KB Ok
40 Correct 3 ms 12892 KB Ok
41 Correct 4 ms 12892 KB Ok
42 Correct 4 ms 12892 KB Ok
43 Correct 3 ms 12892 KB Ok
44 Correct 5 ms 12892 KB Ok
45 Correct 4 ms 12984 KB Ok
46 Correct 5 ms 13060 KB Ok
47 Correct 6 ms 12892 KB Ok
48 Correct 5 ms 13144 KB Ok
49 Correct 5 ms 12888 KB Ok
50 Correct 5 ms 12892 KB Ok
51 Correct 5 ms 13148 KB Ok
52 Correct 5 ms 12888 KB Ok
53 Correct 5 ms 12892 KB Ok
54 Correct 42 ms 17296 KB Ok
55 Correct 47 ms 17236 KB Ok
56 Correct 45 ms 17488 KB Ok
57 Correct 40 ms 16948 KB Ok
58 Correct 55 ms 17324 KB Ok
59 Correct 44 ms 17016 KB Ok
60 Correct 46 ms 16720 KB Ok
61 Correct 36 ms 16980 KB Ok
62 Correct 47 ms 17232 KB Ok
63 Correct 38 ms 16976 KB Ok
64 Correct 52 ms 17500 KB Ok
65 Correct 46 ms 17408 KB Ok
66 Correct 42 ms 16976 KB Ok
67 Correct 35 ms 16720 KB Ok
68 Correct 41 ms 17192 KB Ok
69 Correct 87 ms 21328 KB Ok
70 Correct 98 ms 22644 KB Ok
71 Correct 85 ms 20560 KB Ok
72 Correct 97 ms 21588 KB Ok
73 Correct 82 ms 21072 KB Ok
74 Correct 91 ms 20116 KB Ok
75 Correct 76 ms 20204 KB Ok
76 Correct 93 ms 22104 KB Ok
77 Correct 74 ms 19540 KB Ok
78 Correct 93 ms 22100 KB Ok
79 Correct 87 ms 21332 KB Ok
80 Correct 89 ms 21124 KB Ok
81 Correct 105 ms 21612 KB Ok
82 Correct 93 ms 21328 KB Ok
83 Correct 76 ms 20052 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 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 12632 KB Ok
6 Correct 2 ms 12632 KB Ok
7 Correct 4 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 2 ms 12632 KB Ok
10 Correct 2 ms 12636 KB Ok
11 Correct 2 ms 12636 KB Ok
12 Correct 2 ms 12636 KB Ok
13 Correct 3 ms 12636 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 12636 KB Ok
18 Correct 5 ms 12892 KB Ok
19 Correct 8 ms 13404 KB Ok
20 Correct 7 ms 12892 KB Ok
21 Correct 11 ms 13404 KB Ok
22 Correct 6 ms 13148 KB Ok
23 Correct 3 ms 12636 KB Ok
24 Correct 2 ms 12636 KB Ok
25 Correct 2 ms 12636 KB Ok
26 Correct 2 ms 12632 KB Ok
27 Correct 2 ms 12636 KB Ok
28 Correct 4 ms 12644 KB Ok
29 Correct 3 ms 12636 KB Ok
30 Correct 2 ms 12636 KB Ok
31 Correct 2 ms 12636 KB Ok
32 Correct 2 ms 12732 KB Ok
33 Correct 2 ms 12724 KB Ok
34 Correct 2 ms 12632 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 12636 KB Ok
39 Correct 54 ms 20740 KB Ok
40 Correct 49 ms 21100 KB Ok
41 Correct 85 ms 23224 KB Ok
42 Correct 69 ms 22680 KB Ok
43 Correct 42 ms 18004 KB Ok
44 Correct 81 ms 22552 KB Ok
45 Correct 4 ms 12892 KB Ok
46 Correct 3 ms 12892 KB Ok
47 Correct 4 ms 12888 KB Ok
48 Correct 3 ms 12892 KB Ok
49 Correct 3 ms 12732 KB Ok
50 Correct 3 ms 12892 KB Ok
51 Correct 3 ms 12892 KB Ok
52 Correct 4 ms 12892 KB Ok
53 Correct 4 ms 12892 KB Ok
54 Correct 3 ms 12892 KB Ok
55 Correct 5 ms 12892 KB Ok
56 Correct 4 ms 12984 KB Ok
57 Correct 5 ms 13060 KB Ok
58 Correct 6 ms 12892 KB Ok
59 Correct 5 ms 13144 KB Ok
60 Correct 5 ms 12888 KB Ok
61 Correct 5 ms 12892 KB Ok
62 Correct 5 ms 13148 KB Ok
63 Correct 5 ms 12888 KB Ok
64 Correct 5 ms 12892 KB Ok
65 Correct 42 ms 17296 KB Ok
66 Correct 47 ms 17236 KB Ok
67 Correct 45 ms 17488 KB Ok
68 Correct 40 ms 16948 KB Ok
69 Correct 55 ms 17324 KB Ok
70 Correct 44 ms 17016 KB Ok
71 Correct 46 ms 16720 KB Ok
72 Correct 36 ms 16980 KB Ok
73 Correct 47 ms 17232 KB Ok
74 Correct 38 ms 16976 KB Ok
75 Correct 52 ms 17500 KB Ok
76 Correct 46 ms 17408 KB Ok
77 Correct 42 ms 16976 KB Ok
78 Correct 35 ms 16720 KB Ok
79 Correct 41 ms 17192 KB Ok
80 Correct 87 ms 21328 KB Ok
81 Correct 98 ms 22644 KB Ok
82 Correct 85 ms 20560 KB Ok
83 Correct 97 ms 21588 KB Ok
84 Correct 82 ms 21072 KB Ok
85 Correct 91 ms 20116 KB Ok
86 Correct 76 ms 20204 KB Ok
87 Correct 93 ms 22104 KB Ok
88 Correct 74 ms 19540 KB Ok
89 Correct 93 ms 22100 KB Ok
90 Correct 87 ms 21332 KB Ok
91 Correct 89 ms 21124 KB Ok
92 Correct 105 ms 21612 KB Ok
93 Correct 93 ms 21328 KB Ok
94 Correct 76 ms 20052 KB Ok
95 Correct 128 ms 24404 KB Ok
96 Correct 183 ms 29524 KB Ok
97 Correct 153 ms 26712 KB Ok
98 Correct 108 ms 26836 KB Ok
99 Correct 126 ms 26448 KB Ok
100 Correct 127 ms 25940 KB Ok
101 Correct 151 ms 28288 KB Ok
102 Correct 123 ms 26888 KB Ok
103 Correct 126 ms 27236 KB Ok
104 Correct 147 ms 29012 KB Ok
105 Correct 141 ms 28540 KB Ok
106 Correct 128 ms 28744 KB Ok
107 Correct 135 ms 28240 KB Ok
108 Correct 148 ms 28752 KB Ok
109 Correct 139 ms 29756 KB Ok
110 Correct 627 ms 43504 KB Ok
111 Correct 1010 ms 53324 KB Ok
112 Correct 709 ms 45352 KB Ok
113 Correct 828 ms 49420 KB Ok
114 Correct 986 ms 51016 KB Ok
115 Correct 993 ms 50372 KB Ok
116 Correct 932 ms 50044 KB Ok
117 Correct 915 ms 50740 KB Ok
118 Correct 780 ms 46332 KB Ok
119 Correct 922 ms 51968 KB Ok
120 Correct 740 ms 46672 KB Ok
121 Correct 706 ms 45604 KB Ok
122 Correct 748 ms 48324 KB Ok
123 Correct 1085 ms 53100 KB Ok
124 Correct 638 ms 42156 KB Ok
125 Correct 253 ms 35412 KB Ok