Submission #634062

# Submission time Handle Problem Language Result Execution time Memory
634062 2022-08-23T18:27:56 Z Tob Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 55288 KB
#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

ll nxt() {ll num; cin >> num; return num;}

const int maxn = 4e5 + 7;

int n, m;
bool ndag;
vector <int> v;
int adj[maxn][2];
ll val[maxn], bio[maxn], ps[maxn], siz[maxn], sz[maxn];

void dfs(int x) {
	bio[x] = 1;
	for (int i = 0; i < siz[x]; i++) {
		if (bio[adj[x][i]] == 2) continue;
		if (bio[adj[x][i]] == 1) {
			ndag = 1;
			continue;
		}
		dfs(adj[x][i]);
	}
	bio[x] = 2;
	v.pb(x);
}

bool stask(int ma) {
	for (int i = 0; i <= ma; i++) siz[i] = bio[i] = 0;
	v.clear();
	ndag = 0;
	
	for (int i = 0; i <= ma; i++) {
		if (i + m <= ma) adj[i][siz[i]++] = i+m;
		if (i + n <= ma) adj[i+n][siz[i+n]++] = i;
	}
	
	for (int i = 0; i <= ma; i++) {
		if (!bio[i]) dfs(i);
	}
	
	if (ndag) return 1;
	
	int cc = ma;
	
	for (auto it : v) {
		val[it] = cc--;
	}
	
	for (int i = 1; i <= ma; i++) {
		ps[i] = ps[i-1] + val[i] - val[i-1];
		if (i - m >= 0) {
			if (ps[i] - ps[i-m] <= 0) return 1;
		}
		if (i - n >= 0) {
			if (ps[i] - ps[i-n] >= 0) return 1;
		}
	}
	return 0;
}

void task() {
	cin >> n >> m;

	ll lo = max(n, m) - 1, hi = max(n, m) * 2;
	
	if (n == m) {
		cout << lo << "\n"; 
		for (int i = 1; i <= lo; i++) cout << "1 ";
		cout << "\n";
		return;
	}
	
	while (lo < hi) {
		int mid = (lo + hi + 1) / 2;
		if (stask(mid)) hi = mid - 1;
		else lo = mid;
	}
	
	stask(hi);
	
	cout << hi << "\n";
	
	for (int i = 1; i <= hi; i++) {
		cout << val[i] - val[i-1] << " ";
	}
	cout << "\n";
}

int main () {
	FIO;
	int t;
	
	cin >> t;
	
	while (t--) task();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Ok
2 Correct 0 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 0 ms 340 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 0 ms 340 KB Ok
10 Correct 1 ms 340 KB Ok
11 Correct 0 ms 340 KB Ok
12 Correct 1 ms 212 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Ok
2 Correct 0 ms 340 KB Ok
3 Correct 1 ms 340 KB Ok
4 Correct 1 ms 340 KB Ok
5 Correct 0 ms 340 KB Ok
6 Correct 5 ms 596 KB Ok
7 Correct 28 ms 1972 KB Ok
8 Correct 11 ms 1108 KB Ok
9 Correct 31 ms 2244 KB Ok
10 Correct 16 ms 1376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 2 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 0 ms 340 KB Ok
7 Correct 0 ms 340 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 0 ms 340 KB Ok
10 Correct 1 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 1 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 366 ms 20588 KB Ok
7 Correct 302 ms 23428 KB Ok
8 Correct 596 ms 25300 KB Ok
9 Correct 430 ms 23900 KB Ok
10 Correct 245 ms 14156 KB Ok
11 Correct 484 ms 26056 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Ok
2 Correct 0 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 0 ms 340 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 0 ms 340 KB Ok
10 Correct 1 ms 340 KB Ok
11 Correct 0 ms 340 KB Ok
12 Correct 1 ms 212 KB Ok
13 Correct 0 ms 340 KB Ok
14 Correct 1 ms 340 KB Ok
15 Correct 2 ms 340 KB Ok
16 Correct 0 ms 340 KB Ok
17 Correct 1 ms 340 KB Ok
18 Correct 0 ms 340 KB Ok
19 Correct 0 ms 340 KB Ok
20 Correct 0 ms 340 KB Ok
21 Correct 0 ms 340 KB Ok
22 Correct 1 ms 340 KB Ok
23 Correct 1 ms 340 KB Ok
24 Correct 4 ms 468 KB Ok
25 Correct 5 ms 468 KB Ok
26 Correct 4 ms 468 KB Ok
27 Correct 3 ms 584 KB Ok
28 Correct 3 ms 468 KB Ok
29 Correct 2 ms 468 KB Ok
30 Correct 3 ms 468 KB Ok
31 Correct 4 ms 544 KB Ok
32 Correct 4 ms 468 KB Ok
33 Correct 4 ms 468 KB Ok
34 Correct 10 ms 852 KB Ok
35 Correct 9 ms 852 KB Ok
36 Correct 10 ms 860 KB Ok
37 Correct 10 ms 852 KB Ok
38 Correct 9 ms 852 KB Ok
39 Correct 10 ms 852 KB Ok
40 Correct 11 ms 888 KB Ok
41 Correct 9 ms 852 KB Ok
42 Correct 11 ms 840 KB Ok
43 Correct 10 ms 892 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Ok
2 Correct 0 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 0 ms 340 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 0 ms 340 KB Ok
10 Correct 1 ms 340 KB Ok
11 Correct 0 ms 340 KB Ok
12 Correct 1 ms 212 KB Ok
13 Correct 0 ms 340 KB Ok
14 Correct 0 ms 340 KB Ok
15 Correct 1 ms 340 KB Ok
16 Correct 1 ms 340 KB Ok
17 Correct 0 ms 340 KB Ok
18 Correct 5 ms 596 KB Ok
19 Correct 28 ms 1972 KB Ok
20 Correct 11 ms 1108 KB Ok
21 Correct 31 ms 2244 KB Ok
22 Correct 16 ms 1376 KB Ok
23 Correct 0 ms 340 KB Ok
24 Correct 1 ms 340 KB Ok
25 Correct 2 ms 340 KB Ok
26 Correct 0 ms 340 KB Ok
27 Correct 1 ms 340 KB Ok
28 Correct 0 ms 340 KB Ok
29 Correct 0 ms 340 KB Ok
30 Correct 0 ms 340 KB Ok
31 Correct 0 ms 340 KB Ok
32 Correct 1 ms 340 KB Ok
33 Correct 1 ms 340 KB Ok
34 Correct 4 ms 468 KB Ok
35 Correct 5 ms 468 KB Ok
36 Correct 4 ms 468 KB Ok
37 Correct 3 ms 584 KB Ok
38 Correct 3 ms 468 KB Ok
39 Correct 2 ms 468 KB Ok
40 Correct 3 ms 468 KB Ok
41 Correct 4 ms 544 KB Ok
42 Correct 4 ms 468 KB Ok
43 Correct 4 ms 468 KB Ok
44 Correct 10 ms 852 KB Ok
45 Correct 9 ms 852 KB Ok
46 Correct 10 ms 860 KB Ok
47 Correct 10 ms 852 KB Ok
48 Correct 9 ms 852 KB Ok
49 Correct 10 ms 852 KB Ok
50 Correct 11 ms 888 KB Ok
51 Correct 9 ms 852 KB Ok
52 Correct 11 ms 840 KB Ok
53 Correct 10 ms 892 KB Ok
54 Correct 180 ms 6392 KB Ok
55 Correct 251 ms 7080 KB Ok
56 Correct 227 ms 6852 KB Ok
57 Correct 145 ms 5904 KB Ok
58 Correct 208 ms 6768 KB Ok
59 Correct 190 ms 6348 KB Ok
60 Correct 144 ms 5880 KB Ok
61 Correct 155 ms 6236 KB Ok
62 Correct 260 ms 7252 KB Ok
63 Correct 166 ms 6120 KB Ok
64 Correct 250 ms 6884 KB Ok
65 Correct 211 ms 6828 KB Ok
66 Correct 180 ms 6296 KB Ok
67 Correct 137 ms 5884 KB Ok
68 Correct 210 ms 6692 KB Ok
69 Correct 521 ms 17188 KB Ok
70 Correct 499 ms 17612 KB Ok
71 Correct 490 ms 17284 KB Ok
72 Correct 473 ms 16976 KB Ok
73 Correct 551 ms 17460 KB Ok
74 Correct 510 ms 17056 KB Ok
75 Correct 506 ms 17100 KB Ok
76 Correct 533 ms 17188 KB Ok
77 Correct 485 ms 17248 KB Ok
78 Correct 508 ms 17032 KB Ok
79 Correct 471 ms 17568 KB Ok
80 Correct 463 ms 17184 KB Ok
81 Correct 495 ms 17484 KB Ok
82 Correct 502 ms 17292 KB Ok
83 Correct 486 ms 17284 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Ok
2 Correct 0 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 0 ms 340 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 0 ms 340 KB Ok
10 Correct 1 ms 340 KB Ok
11 Correct 0 ms 340 KB Ok
12 Correct 1 ms 212 KB Ok
13 Correct 0 ms 340 KB Ok
14 Correct 0 ms 340 KB Ok
15 Correct 1 ms 340 KB Ok
16 Correct 1 ms 340 KB Ok
17 Correct 0 ms 340 KB Ok
18 Correct 5 ms 596 KB Ok
19 Correct 28 ms 1972 KB Ok
20 Correct 11 ms 1108 KB Ok
21 Correct 31 ms 2244 KB Ok
22 Correct 16 ms 1376 KB Ok
23 Correct 0 ms 340 KB Ok
24 Correct 1 ms 340 KB Ok
25 Correct 2 ms 340 KB Ok
26 Correct 0 ms 340 KB Ok
27 Correct 1 ms 340 KB Ok
28 Correct 0 ms 340 KB Ok
29 Correct 0 ms 340 KB Ok
30 Correct 0 ms 340 KB Ok
31 Correct 0 ms 340 KB Ok
32 Correct 1 ms 340 KB Ok
33 Correct 1 ms 340 KB Ok
34 Correct 1 ms 336 KB Ok
35 Correct 1 ms 340 KB Ok
36 Correct 1 ms 340 KB Ok
37 Correct 0 ms 340 KB Ok
38 Correct 1 ms 340 KB Ok
39 Correct 366 ms 20588 KB Ok
40 Correct 302 ms 23428 KB Ok
41 Correct 596 ms 25300 KB Ok
42 Correct 430 ms 23900 KB Ok
43 Correct 245 ms 14156 KB Ok
44 Correct 484 ms 26056 KB Ok
45 Correct 4 ms 468 KB Ok
46 Correct 5 ms 468 KB Ok
47 Correct 4 ms 468 KB Ok
48 Correct 3 ms 584 KB Ok
49 Correct 3 ms 468 KB Ok
50 Correct 2 ms 468 KB Ok
51 Correct 3 ms 468 KB Ok
52 Correct 4 ms 544 KB Ok
53 Correct 4 ms 468 KB Ok
54 Correct 4 ms 468 KB Ok
55 Correct 10 ms 852 KB Ok
56 Correct 9 ms 852 KB Ok
57 Correct 10 ms 860 KB Ok
58 Correct 10 ms 852 KB Ok
59 Correct 9 ms 852 KB Ok
60 Correct 10 ms 852 KB Ok
61 Correct 11 ms 888 KB Ok
62 Correct 9 ms 852 KB Ok
63 Correct 11 ms 840 KB Ok
64 Correct 10 ms 892 KB Ok
65 Correct 180 ms 6392 KB Ok
66 Correct 251 ms 7080 KB Ok
67 Correct 227 ms 6852 KB Ok
68 Correct 145 ms 5904 KB Ok
69 Correct 208 ms 6768 KB Ok
70 Correct 190 ms 6348 KB Ok
71 Correct 144 ms 5880 KB Ok
72 Correct 155 ms 6236 KB Ok
73 Correct 260 ms 7252 KB Ok
74 Correct 166 ms 6120 KB Ok
75 Correct 250 ms 6884 KB Ok
76 Correct 211 ms 6828 KB Ok
77 Correct 180 ms 6296 KB Ok
78 Correct 137 ms 5884 KB Ok
79 Correct 210 ms 6692 KB Ok
80 Correct 521 ms 17188 KB Ok
81 Correct 499 ms 17612 KB Ok
82 Correct 490 ms 17284 KB Ok
83 Correct 473 ms 16976 KB Ok
84 Correct 551 ms 17460 KB Ok
85 Correct 510 ms 17056 KB Ok
86 Correct 506 ms 17100 KB Ok
87 Correct 533 ms 17188 KB Ok
88 Correct 485 ms 17248 KB Ok
89 Correct 508 ms 17032 KB Ok
90 Correct 471 ms 17568 KB Ok
91 Correct 463 ms 17184 KB Ok
92 Correct 495 ms 17484 KB Ok
93 Correct 502 ms 17292 KB Ok
94 Correct 486 ms 17284 KB Ok
95 Correct 466 ms 17728 KB Ok
96 Correct 802 ms 24444 KB Ok
97 Correct 813 ms 20872 KB Ok
98 Correct 466 ms 20132 KB Ok
99 Correct 681 ms 19480 KB Ok
100 Correct 729 ms 20380 KB Ok
101 Correct 714 ms 21536 KB Ok
102 Correct 593 ms 20012 KB Ok
103 Correct 648 ms 21904 KB Ok
104 Correct 795 ms 23324 KB Ok
105 Correct 788 ms 24000 KB Ok
106 Correct 518 ms 22236 KB Ok
107 Correct 704 ms 22204 KB Ok
108 Correct 900 ms 24332 KB Ok
109 Correct 723 ms 24044 KB Ok
110 Execution timed out 2096 ms 55288 KB Time limit exceeded
111 Halted 0 ms 0 KB -