Submission #957126

# Submission time Handle Problem Language Result Execution time Memory
957126 2024-04-03T04:30:48 Z pragmatist Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 48208 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, b[N], dp[N];
bool ok;
vector<int> g[N], ord;
int used[N];

void dfs(int v) {
	if(!ok) {
		return;
	}
	used[v] = 1;
	for(auto to : g[v]) {
		if(used[to] == 1) {
			ok = 0;
			return;
		}
		if(!used[to]) {
			dfs(to);
		}
	}
	used[v] = 2;
	ord.push_back(v);
}

bool may(int len) {
	for(int i = 0; i <= len; ++i) {
		g[i].clear();
		used[i] = 0;
		dp[i] = 0;
	}	
	ord.clear();
	for(int i = n; i <= len; ++i) {
		g[i].push_back(i-n);
	}
	for(int i = m; i <= len; ++i) {
		g[i-m].push_back(i);
	}
	ok = 1;
	for(int i = 0; i <= len; ++i) {
		if(!used[i]) {
			dfs(i);
		}
	}
	if(!ok) {
		return 0;
	}
	reverse(ord.begin(), ord.end());
	int timer = 0;
	for(auto i : ord) {
		dp[i] = ++timer;
	}
	for(int i = 0; i <= len; ++i) {
		b[i] = dp[i];
	}
	return 1;
}

void test_case() {
	cin >> n >> m;        
	int l = 0, r = n+m, 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);
	cout << len << "\n";
	for(int i = 1; i <= len; ++i) {
		cout << b[i]-b[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 2 ms 12632 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12636 KB Ok
6 Correct 3 ms 12636 KB Ok
7 Correct 3 ms 12636 KB Ok
8 Correct 3 ms 12776 KB Ok
9 Correct 3 ms 12636 KB Ok
10 Correct 3 ms 12636 KB Ok
11 Correct 3 ms 12636 KB Ok
12 Correct 3 ms 12636 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 3 ms 12632 KB Ok
3 Correct 3 ms 12636 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12772 KB Ok
6 Correct 7 ms 12892 KB Ok
7 Correct 17 ms 13916 KB Ok
8 Correct 9 ms 13148 KB Ok
9 Correct 22 ms 14088 KB Ok
10 Correct 12 ms 13548 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12888 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12632 KB Ok
6 Correct 4 ms 12636 KB Ok
7 Correct 3 ms 12636 KB Ok
8 Correct 2 ms 12636 KB Ok
9 Correct 3 ms 12636 KB Ok
10 Correct 3 ms 12636 KB Ok
11 Correct 3 ms 12636 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Ok
2 Correct 3 ms 12636 KB Ok
3 Correct 3 ms 12632 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 3 ms 12776 KB Ok
6 Correct 214 ms 29928 KB Ok
7 Correct 208 ms 31812 KB Ok
8 Correct 361 ms 33900 KB Ok
9 Correct 310 ms 33092 KB Ok
10 Correct 150 ms 24540 KB Ok
11 Correct 368 ms 34660 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12636 KB Ok
6 Correct 3 ms 12636 KB Ok
7 Correct 3 ms 12636 KB Ok
8 Correct 3 ms 12776 KB Ok
9 Correct 3 ms 12636 KB Ok
10 Correct 3 ms 12636 KB Ok
11 Correct 3 ms 12636 KB Ok
12 Correct 3 ms 12636 KB Ok
13 Correct 2 ms 12636 KB Ok
14 Correct 2 ms 12636 KB Ok
15 Correct 2 ms 12888 KB Ok
16 Correct 3 ms 12636 KB Ok
17 Correct 2 ms 12632 KB Ok
18 Correct 4 ms 12636 KB Ok
19 Correct 3 ms 12636 KB Ok
20 Correct 2 ms 12636 KB Ok
21 Correct 3 ms 12636 KB Ok
22 Correct 3 ms 12636 KB Ok
23 Correct 3 ms 12636 KB Ok
24 Correct 5 ms 12888 KB Ok
25 Correct 7 ms 12888 KB Ok
26 Correct 5 ms 12892 KB Ok
27 Correct 5 ms 12892 KB Ok
28 Correct 5 ms 12892 KB Ok
29 Correct 4 ms 12944 KB Ok
30 Correct 4 ms 12888 KB Ok
31 Correct 5 ms 12892 KB Ok
32 Correct 5 ms 12892 KB Ok
33 Correct 5 ms 12888 KB Ok
34 Correct 9 ms 13148 KB Ok
35 Correct 9 ms 13056 KB Ok
36 Correct 11 ms 13404 KB Ok
37 Correct 12 ms 13292 KB Ok
38 Correct 9 ms 13148 KB Ok
39 Correct 9 ms 13144 KB Ok
40 Correct 10 ms 13148 KB Ok
41 Correct 9 ms 13148 KB Ok
42 Correct 9 ms 13148 KB Ok
43 Correct 11 ms 13148 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12636 KB Ok
6 Correct 3 ms 12636 KB Ok
7 Correct 3 ms 12636 KB Ok
8 Correct 3 ms 12776 KB Ok
9 Correct 3 ms 12636 KB Ok
10 Correct 3 ms 12636 KB Ok
11 Correct 3 ms 12636 KB Ok
12 Correct 3 ms 12636 KB Ok
13 Correct 3 ms 12636 KB Ok
14 Correct 3 ms 12632 KB Ok
15 Correct 3 ms 12636 KB Ok
16 Correct 3 ms 12636 KB Ok
17 Correct 2 ms 12772 KB Ok
18 Correct 7 ms 12892 KB Ok
19 Correct 17 ms 13916 KB Ok
20 Correct 9 ms 13148 KB Ok
21 Correct 22 ms 14088 KB Ok
22 Correct 12 ms 13548 KB Ok
23 Correct 2 ms 12636 KB Ok
24 Correct 2 ms 12636 KB Ok
25 Correct 2 ms 12888 KB Ok
26 Correct 3 ms 12636 KB Ok
27 Correct 2 ms 12632 KB Ok
28 Correct 4 ms 12636 KB Ok
29 Correct 3 ms 12636 KB Ok
30 Correct 2 ms 12636 KB Ok
31 Correct 3 ms 12636 KB Ok
32 Correct 3 ms 12636 KB Ok
33 Correct 3 ms 12636 KB Ok
34 Correct 5 ms 12888 KB Ok
35 Correct 7 ms 12888 KB Ok
36 Correct 5 ms 12892 KB Ok
37 Correct 5 ms 12892 KB Ok
38 Correct 5 ms 12892 KB Ok
39 Correct 4 ms 12944 KB Ok
40 Correct 4 ms 12888 KB Ok
41 Correct 5 ms 12892 KB Ok
42 Correct 5 ms 12892 KB Ok
43 Correct 5 ms 12888 KB Ok
44 Correct 9 ms 13148 KB Ok
45 Correct 9 ms 13056 KB Ok
46 Correct 11 ms 13404 KB Ok
47 Correct 12 ms 13292 KB Ok
48 Correct 9 ms 13148 KB Ok
49 Correct 9 ms 13144 KB Ok
50 Correct 10 ms 13148 KB Ok
51 Correct 9 ms 13148 KB Ok
52 Correct 9 ms 13148 KB Ok
53 Correct 11 ms 13148 KB Ok
54 Correct 122 ms 18464 KB Ok
55 Correct 146 ms 18912 KB Ok
56 Correct 143 ms 18896 KB Ok
57 Correct 121 ms 17936 KB Ok
58 Correct 139 ms 18900 KB Ok
59 Correct 127 ms 18620 KB Ok
60 Correct 111 ms 18000 KB Ok
61 Correct 99 ms 18248 KB Ok
62 Correct 154 ms 19144 KB Ok
63 Correct 126 ms 18384 KB Ok
64 Correct 151 ms 18896 KB Ok
65 Correct 137 ms 18892 KB Ok
66 Correct 115 ms 18400 KB Ok
67 Correct 105 ms 18056 KB Ok
68 Correct 135 ms 18640 KB Ok
69 Correct 455 ms 27480 KB Ok
70 Correct 493 ms 27952 KB Ok
71 Correct 480 ms 27608 KB Ok
72 Correct 433 ms 27408 KB Ok
73 Correct 464 ms 27856 KB Ok
74 Correct 403 ms 27600 KB Ok
75 Correct 421 ms 27548 KB Ok
76 Correct 459 ms 27728 KB Ok
77 Correct 436 ms 27600 KB Ok
78 Correct 453 ms 27312 KB Ok
79 Correct 448 ms 27860 KB Ok
80 Correct 461 ms 27424 KB Ok
81 Correct 429 ms 27840 KB Ok
82 Correct 476 ms 27728 KB Ok
83 Correct 478 ms 27688 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Ok
2 Correct 2 ms 12636 KB Ok
3 Correct 2 ms 12636 KB Ok
4 Correct 3 ms 12636 KB Ok
5 Correct 2 ms 12636 KB Ok
6 Correct 3 ms 12636 KB Ok
7 Correct 3 ms 12636 KB Ok
8 Correct 3 ms 12776 KB Ok
9 Correct 3 ms 12636 KB Ok
10 Correct 3 ms 12636 KB Ok
11 Correct 3 ms 12636 KB Ok
12 Correct 3 ms 12636 KB Ok
13 Correct 3 ms 12636 KB Ok
14 Correct 3 ms 12632 KB Ok
15 Correct 3 ms 12636 KB Ok
16 Correct 3 ms 12636 KB Ok
17 Correct 2 ms 12772 KB Ok
18 Correct 7 ms 12892 KB Ok
19 Correct 17 ms 13916 KB Ok
20 Correct 9 ms 13148 KB Ok
21 Correct 22 ms 14088 KB Ok
22 Correct 12 ms 13548 KB Ok
23 Correct 2 ms 12636 KB Ok
24 Correct 2 ms 12636 KB Ok
25 Correct 2 ms 12888 KB Ok
26 Correct 3 ms 12636 KB Ok
27 Correct 2 ms 12632 KB Ok
28 Correct 4 ms 12636 KB Ok
29 Correct 3 ms 12636 KB Ok
30 Correct 2 ms 12636 KB Ok
31 Correct 3 ms 12636 KB Ok
32 Correct 3 ms 12636 KB Ok
33 Correct 3 ms 12636 KB Ok
34 Correct 3 ms 12636 KB Ok
35 Correct 3 ms 12636 KB Ok
36 Correct 3 ms 12632 KB Ok
37 Correct 3 ms 12636 KB Ok
38 Correct 3 ms 12776 KB Ok
39 Correct 214 ms 29928 KB Ok
40 Correct 208 ms 31812 KB Ok
41 Correct 361 ms 33900 KB Ok
42 Correct 310 ms 33092 KB Ok
43 Correct 150 ms 24540 KB Ok
44 Correct 368 ms 34660 KB Ok
45 Correct 5 ms 12888 KB Ok
46 Correct 7 ms 12888 KB Ok
47 Correct 5 ms 12892 KB Ok
48 Correct 5 ms 12892 KB Ok
49 Correct 5 ms 12892 KB Ok
50 Correct 4 ms 12944 KB Ok
51 Correct 4 ms 12888 KB Ok
52 Correct 5 ms 12892 KB Ok
53 Correct 5 ms 12892 KB Ok
54 Correct 5 ms 12888 KB Ok
55 Correct 9 ms 13148 KB Ok
56 Correct 9 ms 13056 KB Ok
57 Correct 11 ms 13404 KB Ok
58 Correct 12 ms 13292 KB Ok
59 Correct 9 ms 13148 KB Ok
60 Correct 9 ms 13144 KB Ok
61 Correct 10 ms 13148 KB Ok
62 Correct 9 ms 13148 KB Ok
63 Correct 9 ms 13148 KB Ok
64 Correct 11 ms 13148 KB Ok
65 Correct 122 ms 18464 KB Ok
66 Correct 146 ms 18912 KB Ok
67 Correct 143 ms 18896 KB Ok
68 Correct 121 ms 17936 KB Ok
69 Correct 139 ms 18900 KB Ok
70 Correct 127 ms 18620 KB Ok
71 Correct 111 ms 18000 KB Ok
72 Correct 99 ms 18248 KB Ok
73 Correct 154 ms 19144 KB Ok
74 Correct 126 ms 18384 KB Ok
75 Correct 151 ms 18896 KB Ok
76 Correct 137 ms 18892 KB Ok
77 Correct 115 ms 18400 KB Ok
78 Correct 105 ms 18056 KB Ok
79 Correct 135 ms 18640 KB Ok
80 Correct 455 ms 27480 KB Ok
81 Correct 493 ms 27952 KB Ok
82 Correct 480 ms 27608 KB Ok
83 Correct 433 ms 27408 KB Ok
84 Correct 464 ms 27856 KB Ok
85 Correct 403 ms 27600 KB Ok
86 Correct 421 ms 27548 KB Ok
87 Correct 459 ms 27728 KB Ok
88 Correct 436 ms 27600 KB Ok
89 Correct 453 ms 27312 KB Ok
90 Correct 448 ms 27860 KB Ok
91 Correct 461 ms 27424 KB Ok
92 Correct 429 ms 27840 KB Ok
93 Correct 476 ms 27728 KB Ok
94 Correct 478 ms 27688 KB Ok
95 Correct 371 ms 28100 KB Ok
96 Correct 591 ms 35732 KB Ok
97 Correct 529 ms 31792 KB Ok
98 Correct 369 ms 31012 KB Ok
99 Correct 446 ms 30936 KB Ok
100 Correct 499 ms 31128 KB Ok
101 Correct 480 ms 32956 KB Ok
102 Correct 495 ms 31408 KB Ok
103 Correct 515 ms 32968 KB Ok
104 Correct 594 ms 34212 KB Ok
105 Correct 631 ms 34900 KB Ok
106 Correct 480 ms 33728 KB Ok
107 Correct 550 ms 33728 KB Ok
108 Correct 607 ms 35008 KB Ok
109 Correct 506 ms 35012 KB Ok
110 Execution timed out 2027 ms 48208 KB Time limit exceeded
111 Halted 0 ms 0 KB -