Submission #957141

# Submission time Handle Problem Language Result Execution time Memory
957141 2024-04-03T05:03:04 Z pragmatist Nice sequence (IZhO18_sequence) C++17
100 / 100
973 ms 60284 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)4e5+20;
const int inf = (int)1e9+7;
const long long INF = (long long)1e18+7;
const int MOD = 42043;

int sum(int x, int y) {
	x += y;
	if(x >= MOD) {
		x -= MOD;
	}
	return x;
}

int mult(int x, int y) {
	return 1ll*x*y%MOD;
}

int n, m, o, dp[N];
bool ok;
vector<int> g[N], ord, ans;
int used[N];

void dfs(int v) {
	used[v] = 1;
	if(!ok) {
		return;
	}
	if(v-n>=0 && used[v-n]==1) {
		ok = 0;
		return;
	}
	if(v-n>=0 && !used[v-n]) {
		dfs(v-n);
	}
	if(v+m<=o && used[v+m]==1) {
		ok = 0;
		return;
	}
	if(v+m<=o && !used[v+m]) {
		dfs(v+m);
	}

	used[v] = 2;
	ord.push_back(v);
}

bool may(int len) {
	o = len;
	for(int i = 0; i <= len; ++i) {
		used[i] = 0;
		dp[i] = 0;
	}	
	ord.clear();
	ok = 1;
	for(int i = 0; i <= len; ++i) {
		if(!used[i]) {
			dfs(i);
		}
	}
	if(!ok) {
		return 0;
	}
	ans = ord;
	return 1;
}

void test_case() {
	cin >> n >> m;        
	int l = 0, r = 4e5, len = -1;
	while(l <= r) {
		int mid = (l+r)/2;
		if(may(mid)) {
			len = mid;
			l = mid+1;
		} else {
			r = mid-1;
		}
	}	   
	assert(len != -1);
	reverse(ans.begin(), ans.end());
	int timer = 0;
	for(auto i : ans) {
		dp[i] = ++timer;
	}
	cout << len << "\n";
	for(int i = 1; i <= len; ++i) {
		cout << dp[i]-dp[i-1] << ' ';
	}
	cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
    	test_case();
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12888 KB Ok
2 Correct 14 ms 12888 KB Ok
3 Correct 15 ms 12892 KB Ok
4 Correct 16 ms 12944 KB Ok
5 Correct 14 ms 12892 KB Ok
6 Correct 14 ms 12948 KB Ok
7 Correct 14 ms 12888 KB Ok
8 Correct 14 ms 12892 KB Ok
9 Correct 15 ms 12948 KB Ok
10 Correct 14 ms 12892 KB Ok
11 Correct 15 ms 12952 KB Ok
12 Correct 14 ms 12892 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12888 KB Ok
2 Correct 15 ms 12892 KB Ok
3 Correct 15 ms 12944 KB Ok
4 Correct 15 ms 12892 KB Ok
5 Correct 13 ms 12892 KB Ok
6 Correct 16 ms 12892 KB Ok
7 Correct 25 ms 13660 KB Ok
8 Correct 18 ms 13148 KB Ok
9 Correct 26 ms 13660 KB Ok
10 Correct 20 ms 13404 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12888 KB Ok
2 Correct 15 ms 13148 KB Ok
3 Correct 14 ms 12952 KB Ok
4 Correct 15 ms 12892 KB Ok
5 Correct 14 ms 12892 KB Ok
6 Correct 14 ms 12892 KB Ok
7 Correct 14 ms 12948 KB Ok
8 Correct 14 ms 12892 KB Ok
9 Correct 14 ms 12892 KB Ok
10 Correct 14 ms 12724 KB Ok
11 Correct 14 ms 12888 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12940 KB Ok
2 Correct 16 ms 13140 KB Ok
3 Correct 13 ms 12888 KB Ok
4 Correct 14 ms 12948 KB Ok
5 Correct 15 ms 13148 KB Ok
6 Correct 194 ms 23584 KB Ok
7 Correct 160 ms 22700 KB Ok
8 Correct 265 ms 26372 KB Ok
9 Correct 211 ms 25980 KB Ok
10 Correct 165 ms 19916 KB Ok
11 Correct 218 ms 26120 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12888 KB Ok
2 Correct 14 ms 12888 KB Ok
3 Correct 15 ms 12892 KB Ok
4 Correct 16 ms 12944 KB Ok
5 Correct 14 ms 12892 KB Ok
6 Correct 14 ms 12948 KB Ok
7 Correct 14 ms 12888 KB Ok
8 Correct 14 ms 12892 KB Ok
9 Correct 15 ms 12948 KB Ok
10 Correct 14 ms 12892 KB Ok
11 Correct 15 ms 12952 KB Ok
12 Correct 14 ms 12892 KB Ok
13 Correct 6 ms 12888 KB Ok
14 Correct 15 ms 13148 KB Ok
15 Correct 14 ms 12952 KB Ok
16 Correct 15 ms 12892 KB Ok
17 Correct 14 ms 12892 KB Ok
18 Correct 14 ms 12892 KB Ok
19 Correct 14 ms 12948 KB Ok
20 Correct 14 ms 12892 KB Ok
21 Correct 14 ms 12892 KB Ok
22 Correct 14 ms 12724 KB Ok
23 Correct 14 ms 12888 KB Ok
24 Correct 15 ms 12892 KB Ok
25 Correct 15 ms 13036 KB Ok
26 Correct 16 ms 13052 KB Ok
27 Correct 15 ms 13052 KB Ok
28 Correct 15 ms 13036 KB Ok
29 Correct 15 ms 12892 KB Ok
30 Correct 15 ms 13016 KB Ok
31 Correct 15 ms 12892 KB Ok
32 Correct 18 ms 12888 KB Ok
33 Correct 16 ms 12892 KB Ok
34 Correct 18 ms 13144 KB Ok
35 Correct 20 ms 13148 KB Ok
36 Correct 19 ms 13148 KB Ok
37 Correct 19 ms 13240 KB Ok
38 Correct 19 ms 13148 KB Ok
39 Correct 18 ms 13148 KB Ok
40 Correct 21 ms 13148 KB Ok
41 Correct 20 ms 13248 KB Ok
42 Correct 20 ms 13200 KB Ok
43 Correct 20 ms 13144 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12888 KB Ok
2 Correct 14 ms 12888 KB Ok
3 Correct 15 ms 12892 KB Ok
4 Correct 16 ms 12944 KB Ok
5 Correct 14 ms 12892 KB Ok
6 Correct 14 ms 12948 KB Ok
7 Correct 14 ms 12888 KB Ok
8 Correct 14 ms 12892 KB Ok
9 Correct 15 ms 12948 KB Ok
10 Correct 14 ms 12892 KB Ok
11 Correct 15 ms 12952 KB Ok
12 Correct 14 ms 12892 KB Ok
13 Correct 14 ms 12888 KB Ok
14 Correct 15 ms 12892 KB Ok
15 Correct 15 ms 12944 KB Ok
16 Correct 15 ms 12892 KB Ok
17 Correct 13 ms 12892 KB Ok
18 Correct 16 ms 12892 KB Ok
19 Correct 25 ms 13660 KB Ok
20 Correct 18 ms 13148 KB Ok
21 Correct 26 ms 13660 KB Ok
22 Correct 20 ms 13404 KB Ok
23 Correct 6 ms 12888 KB Ok
24 Correct 15 ms 13148 KB Ok
25 Correct 14 ms 12952 KB Ok
26 Correct 15 ms 12892 KB Ok
27 Correct 14 ms 12892 KB Ok
28 Correct 14 ms 12892 KB Ok
29 Correct 14 ms 12948 KB Ok
30 Correct 14 ms 12892 KB Ok
31 Correct 14 ms 12892 KB Ok
32 Correct 14 ms 12724 KB Ok
33 Correct 14 ms 12888 KB Ok
34 Correct 15 ms 12892 KB Ok
35 Correct 15 ms 13036 KB Ok
36 Correct 16 ms 13052 KB Ok
37 Correct 15 ms 13052 KB Ok
38 Correct 15 ms 13036 KB Ok
39 Correct 15 ms 12892 KB Ok
40 Correct 15 ms 13016 KB Ok
41 Correct 15 ms 12892 KB Ok
42 Correct 18 ms 12888 KB Ok
43 Correct 16 ms 12892 KB Ok
44 Correct 18 ms 13144 KB Ok
45 Correct 20 ms 13148 KB Ok
46 Correct 19 ms 13148 KB Ok
47 Correct 19 ms 13240 KB Ok
48 Correct 19 ms 13148 KB Ok
49 Correct 18 ms 13148 KB Ok
50 Correct 21 ms 13148 KB Ok
51 Correct 20 ms 13248 KB Ok
52 Correct 20 ms 13200 KB Ok
53 Correct 20 ms 13144 KB Ok
54 Correct 81 ms 16364 KB Ok
55 Correct 94 ms 16796 KB Ok
56 Correct 104 ms 16204 KB Ok
57 Correct 72 ms 15668 KB Ok
58 Correct 91 ms 16612 KB Ok
59 Correct 84 ms 15904 KB Ok
60 Correct 75 ms 15804 KB Ok
61 Correct 78 ms 16280 KB Ok
62 Correct 97 ms 16416 KB Ok
63 Correct 80 ms 15976 KB Ok
64 Correct 94 ms 16356 KB Ok
65 Correct 90 ms 16700 KB Ok
66 Correct 80 ms 16472 KB Ok
67 Correct 75 ms 15592 KB Ok
68 Correct 106 ms 16228 KB Ok
69 Correct 196 ms 23108 KB Ok
70 Correct 208 ms 23724 KB Ok
71 Correct 195 ms 23396 KB Ok
72 Correct 234 ms 23608 KB Ok
73 Correct 206 ms 23172 KB Ok
74 Correct 187 ms 23040 KB Ok
75 Correct 184 ms 23268 KB Ok
76 Correct 212 ms 23008 KB Ok
77 Correct 184 ms 23524 KB Ok
78 Correct 213 ms 23184 KB Ok
79 Correct 196 ms 23956 KB Ok
80 Correct 212 ms 22976 KB Ok
81 Correct 194 ms 23448 KB Ok
82 Correct 217 ms 23600 KB Ok
83 Correct 186 ms 23424 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12888 KB Ok
2 Correct 14 ms 12888 KB Ok
3 Correct 15 ms 12892 KB Ok
4 Correct 16 ms 12944 KB Ok
5 Correct 14 ms 12892 KB Ok
6 Correct 14 ms 12948 KB Ok
7 Correct 14 ms 12888 KB Ok
8 Correct 14 ms 12892 KB Ok
9 Correct 15 ms 12948 KB Ok
10 Correct 14 ms 12892 KB Ok
11 Correct 15 ms 12952 KB Ok
12 Correct 14 ms 12892 KB Ok
13 Correct 14 ms 12888 KB Ok
14 Correct 15 ms 12892 KB Ok
15 Correct 15 ms 12944 KB Ok
16 Correct 15 ms 12892 KB Ok
17 Correct 13 ms 12892 KB Ok
18 Correct 16 ms 12892 KB Ok
19 Correct 25 ms 13660 KB Ok
20 Correct 18 ms 13148 KB Ok
21 Correct 26 ms 13660 KB Ok
22 Correct 20 ms 13404 KB Ok
23 Correct 6 ms 12888 KB Ok
24 Correct 15 ms 13148 KB Ok
25 Correct 14 ms 12952 KB Ok
26 Correct 15 ms 12892 KB Ok
27 Correct 14 ms 12892 KB Ok
28 Correct 14 ms 12892 KB Ok
29 Correct 14 ms 12948 KB Ok
30 Correct 14 ms 12892 KB Ok
31 Correct 14 ms 12892 KB Ok
32 Correct 14 ms 12724 KB Ok
33 Correct 14 ms 12888 KB Ok
34 Correct 15 ms 12940 KB Ok
35 Correct 16 ms 13140 KB Ok
36 Correct 13 ms 12888 KB Ok
37 Correct 14 ms 12948 KB Ok
38 Correct 15 ms 13148 KB Ok
39 Correct 194 ms 23584 KB Ok
40 Correct 160 ms 22700 KB Ok
41 Correct 265 ms 26372 KB Ok
42 Correct 211 ms 25980 KB Ok
43 Correct 165 ms 19916 KB Ok
44 Correct 218 ms 26120 KB Ok
45 Correct 15 ms 12892 KB Ok
46 Correct 15 ms 13036 KB Ok
47 Correct 16 ms 13052 KB Ok
48 Correct 15 ms 13052 KB Ok
49 Correct 15 ms 13036 KB Ok
50 Correct 15 ms 12892 KB Ok
51 Correct 15 ms 13016 KB Ok
52 Correct 15 ms 12892 KB Ok
53 Correct 18 ms 12888 KB Ok
54 Correct 16 ms 12892 KB Ok
55 Correct 18 ms 13144 KB Ok
56 Correct 20 ms 13148 KB Ok
57 Correct 19 ms 13148 KB Ok
58 Correct 19 ms 13240 KB Ok
59 Correct 19 ms 13148 KB Ok
60 Correct 18 ms 13148 KB Ok
61 Correct 21 ms 13148 KB Ok
62 Correct 20 ms 13248 KB Ok
63 Correct 20 ms 13200 KB Ok
64 Correct 20 ms 13144 KB Ok
65 Correct 81 ms 16364 KB Ok
66 Correct 94 ms 16796 KB Ok
67 Correct 104 ms 16204 KB Ok
68 Correct 72 ms 15668 KB Ok
69 Correct 91 ms 16612 KB Ok
70 Correct 84 ms 15904 KB Ok
71 Correct 75 ms 15804 KB Ok
72 Correct 78 ms 16280 KB Ok
73 Correct 97 ms 16416 KB Ok
74 Correct 80 ms 15976 KB Ok
75 Correct 94 ms 16356 KB Ok
76 Correct 90 ms 16700 KB Ok
77 Correct 80 ms 16472 KB Ok
78 Correct 75 ms 15592 KB Ok
79 Correct 106 ms 16228 KB Ok
80 Correct 196 ms 23108 KB Ok
81 Correct 208 ms 23724 KB Ok
82 Correct 195 ms 23396 KB Ok
83 Correct 234 ms 23608 KB Ok
84 Correct 206 ms 23172 KB Ok
85 Correct 187 ms 23040 KB Ok
86 Correct 184 ms 23268 KB Ok
87 Correct 212 ms 23008 KB Ok
88 Correct 184 ms 23524 KB Ok
89 Correct 213 ms 23184 KB Ok
90 Correct 196 ms 23956 KB Ok
91 Correct 212 ms 22976 KB Ok
92 Correct 194 ms 23448 KB Ok
93 Correct 217 ms 23600 KB Ok
94 Correct 186 ms 23424 KB Ok
95 Correct 220 ms 20480 KB Ok
96 Correct 291 ms 25504 KB Ok
97 Correct 285 ms 22948 KB Ok
98 Correct 226 ms 22404 KB Ok
99 Correct 244 ms 21764 KB Ok
100 Correct 281 ms 22664 KB Ok
101 Correct 276 ms 25024 KB Ok
102 Correct 247 ms 23436 KB Ok
103 Correct 250 ms 22828 KB Ok
104 Correct 295 ms 26388 KB Ok
105 Correct 277 ms 24940 KB Ok
106 Correct 239 ms 25196 KB Ok
107 Correct 297 ms 23300 KB Ok
108 Correct 287 ms 25744 KB Ok
109 Correct 260 ms 23532 KB Ok
110 Correct 764 ms 57688 KB Ok
111 Correct 935 ms 57744 KB Ok
112 Correct 826 ms 58256 KB Ok
113 Correct 877 ms 55496 KB Ok
114 Correct 862 ms 58676 KB Ok
115 Correct 883 ms 59644 KB Ok
116 Correct 875 ms 60268 KB Ok
117 Correct 928 ms 57204 KB Ok
118 Correct 848 ms 60284 KB Ok
119 Correct 973 ms 55816 KB Ok
120 Correct 863 ms 55996 KB Ok
121 Correct 806 ms 55300 KB Ok
122 Correct 865 ms 59244 KB Ok
123 Correct 952 ms 56380 KB Ok
124 Correct 718 ms 58624 KB Ok
125 Correct 855 ms 41964 KB Ok