Submission #634066

# Submission time Handle Problem Language Result Execution time Memory
634066 2022-08-23T18:32:52 Z Tob Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 38752 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, ss;
bool ndag;
int adj[maxn][2];
ll val[maxn], bio[maxn], ps[maxn], siz[maxn], v[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[ss++] = x;
}

bool stask(int ma) {
	for (int i = 0; i <= ma; i++) siz[i] = bio[i] = 0;
	ss = 0;
	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 (int i = 0; i <= ma; i++) {
		val[v[i]] = 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 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 1 ms 340 KB Ok
7 Correct 1 ms 328 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Ok
2 Correct 0 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 4 ms 596 KB Ok
7 Correct 23 ms 1744 KB Ok
8 Correct 9 ms 980 KB Ok
9 Correct 25 ms 1960 KB Ok
10 Correct 14 ms 1236 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 0 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 1 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 340 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 0 ms 340 KB Ok
6 Correct 321 ms 18876 KB Ok
7 Correct 264 ms 20936 KB Ok
8 Correct 531 ms 23048 KB Ok
9 Correct 406 ms 21804 KB Ok
10 Correct 230 ms 12972 KB Ok
11 Correct 415 ms 23644 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 1 ms 340 KB Ok
7 Correct 1 ms 328 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 1 ms 340 KB Ok
14 Correct 1 ms 340 KB Ok
15 Correct 0 ms 340 KB Ok
16 Correct 0 ms 340 KB Ok
17 Correct 0 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 1 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 4 ms 468 KB Ok
26 Correct 4 ms 468 KB Ok
27 Correct 4 ms 468 KB Ok
28 Correct 3 ms 468 KB Ok
29 Correct 3 ms 476 KB Ok
30 Correct 3 ms 468 KB Ok
31 Correct 4 ms 468 KB Ok
32 Correct 4 ms 468 KB Ok
33 Correct 3 ms 468 KB Ok
34 Correct 10 ms 820 KB Ok
35 Correct 8 ms 852 KB Ok
36 Correct 9 ms 864 KB Ok
37 Correct 9 ms 852 KB Ok
38 Correct 8 ms 784 KB Ok
39 Correct 9 ms 852 KB Ok
40 Correct 11 ms 868 KB Ok
41 Correct 10 ms 852 KB Ok
42 Correct 10 ms 852 KB Ok
43 Correct 10 ms 868 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 1 ms 340 KB Ok
7 Correct 1 ms 328 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 1 ms 340 KB Ok
14 Correct 0 ms 340 KB Ok
15 Correct 1 ms 340 KB Ok
16 Correct 0 ms 340 KB Ok
17 Correct 1 ms 340 KB Ok
18 Correct 4 ms 596 KB Ok
19 Correct 23 ms 1744 KB Ok
20 Correct 9 ms 980 KB Ok
21 Correct 25 ms 1960 KB Ok
22 Correct 14 ms 1236 KB Ok
23 Correct 1 ms 340 KB Ok
24 Correct 1 ms 340 KB Ok
25 Correct 0 ms 340 KB Ok
26 Correct 0 ms 340 KB Ok
27 Correct 0 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 1 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 4 ms 468 KB Ok
36 Correct 4 ms 468 KB Ok
37 Correct 4 ms 468 KB Ok
38 Correct 3 ms 468 KB Ok
39 Correct 3 ms 476 KB Ok
40 Correct 3 ms 468 KB Ok
41 Correct 4 ms 468 KB Ok
42 Correct 4 ms 468 KB Ok
43 Correct 3 ms 468 KB Ok
44 Correct 10 ms 820 KB Ok
45 Correct 8 ms 852 KB Ok
46 Correct 9 ms 864 KB Ok
47 Correct 9 ms 852 KB Ok
48 Correct 8 ms 784 KB Ok
49 Correct 9 ms 852 KB Ok
50 Correct 11 ms 868 KB Ok
51 Correct 10 ms 852 KB Ok
52 Correct 10 ms 852 KB Ok
53 Correct 10 ms 868 KB Ok
54 Correct 164 ms 6624 KB Ok
55 Correct 225 ms 7204 KB Ok
56 Correct 203 ms 7076 KB Ok
57 Correct 133 ms 6032 KB Ok
58 Correct 193 ms 6932 KB Ok
59 Correct 182 ms 6592 KB Ok
60 Correct 134 ms 6188 KB Ok
61 Correct 142 ms 6456 KB Ok
62 Correct 240 ms 7476 KB Ok
63 Correct 159 ms 6300 KB Ok
64 Correct 232 ms 7112 KB Ok
65 Correct 194 ms 6988 KB Ok
66 Correct 159 ms 6592 KB Ok
67 Correct 123 ms 6140 KB Ok
68 Correct 196 ms 6860 KB Ok
69 Correct 496 ms 15800 KB Ok
70 Correct 477 ms 16264 KB Ok
71 Correct 494 ms 15836 KB Ok
72 Correct 479 ms 15708 KB Ok
73 Correct 479 ms 16092 KB Ok
74 Correct 461 ms 15712 KB Ok
75 Correct 461 ms 15684 KB Ok
76 Correct 488 ms 15868 KB Ok
77 Correct 480 ms 15792 KB Ok
78 Correct 531 ms 15696 KB Ok
79 Correct 465 ms 16184 KB Ok
80 Correct 461 ms 15892 KB Ok
81 Correct 450 ms 16164 KB Ok
82 Correct 509 ms 15936 KB Ok
83 Correct 484 ms 15904 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 1 ms 340 KB Ok
7 Correct 1 ms 328 KB Ok
8 Correct 0 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 1 ms 340 KB Ok
14 Correct 0 ms 340 KB Ok
15 Correct 1 ms 340 KB Ok
16 Correct 0 ms 340 KB Ok
17 Correct 1 ms 340 KB Ok
18 Correct 4 ms 596 KB Ok
19 Correct 23 ms 1744 KB Ok
20 Correct 9 ms 980 KB Ok
21 Correct 25 ms 1960 KB Ok
22 Correct 14 ms 1236 KB Ok
23 Correct 1 ms 340 KB Ok
24 Correct 1 ms 340 KB Ok
25 Correct 0 ms 340 KB Ok
26 Correct 0 ms 340 KB Ok
27 Correct 0 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 1 ms 340 KB Ok
32 Correct 1 ms 340 KB Ok
33 Correct 1 ms 340 KB Ok
34 Correct 1 ms 340 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 0 ms 340 KB Ok
39 Correct 321 ms 18876 KB Ok
40 Correct 264 ms 20936 KB Ok
41 Correct 531 ms 23048 KB Ok
42 Correct 406 ms 21804 KB Ok
43 Correct 230 ms 12972 KB Ok
44 Correct 415 ms 23644 KB Ok
45 Correct 4 ms 468 KB Ok
46 Correct 4 ms 468 KB Ok
47 Correct 4 ms 468 KB Ok
48 Correct 4 ms 468 KB Ok
49 Correct 3 ms 468 KB Ok
50 Correct 3 ms 476 KB Ok
51 Correct 3 ms 468 KB Ok
52 Correct 4 ms 468 KB Ok
53 Correct 4 ms 468 KB Ok
54 Correct 3 ms 468 KB Ok
55 Correct 10 ms 820 KB Ok
56 Correct 8 ms 852 KB Ok
57 Correct 9 ms 864 KB Ok
58 Correct 9 ms 852 KB Ok
59 Correct 8 ms 784 KB Ok
60 Correct 9 ms 852 KB Ok
61 Correct 11 ms 868 KB Ok
62 Correct 10 ms 852 KB Ok
63 Correct 10 ms 852 KB Ok
64 Correct 10 ms 868 KB Ok
65 Correct 164 ms 6624 KB Ok
66 Correct 225 ms 7204 KB Ok
67 Correct 203 ms 7076 KB Ok
68 Correct 133 ms 6032 KB Ok
69 Correct 193 ms 6932 KB Ok
70 Correct 182 ms 6592 KB Ok
71 Correct 134 ms 6188 KB Ok
72 Correct 142 ms 6456 KB Ok
73 Correct 240 ms 7476 KB Ok
74 Correct 159 ms 6300 KB Ok
75 Correct 232 ms 7112 KB Ok
76 Correct 194 ms 6988 KB Ok
77 Correct 159 ms 6592 KB Ok
78 Correct 123 ms 6140 KB Ok
79 Correct 196 ms 6860 KB Ok
80 Correct 496 ms 15800 KB Ok
81 Correct 477 ms 16264 KB Ok
82 Correct 494 ms 15836 KB Ok
83 Correct 479 ms 15708 KB Ok
84 Correct 479 ms 16092 KB Ok
85 Correct 461 ms 15712 KB Ok
86 Correct 461 ms 15684 KB Ok
87 Correct 488 ms 15868 KB Ok
88 Correct 480 ms 15792 KB Ok
89 Correct 531 ms 15696 KB Ok
90 Correct 465 ms 16184 KB Ok
91 Correct 461 ms 15892 KB Ok
92 Correct 450 ms 16164 KB Ok
93 Correct 509 ms 15936 KB Ok
94 Correct 484 ms 15904 KB Ok
95 Correct 435 ms 18704 KB Ok
96 Correct 763 ms 25636 KB Ok
97 Correct 804 ms 21832 KB Ok
98 Correct 463 ms 21360 KB Ok
99 Correct 646 ms 20656 KB Ok
100 Correct 691 ms 21640 KB Ok
101 Correct 706 ms 23016 KB Ok
102 Correct 593 ms 21076 KB Ok
103 Correct 657 ms 23096 KB Ok
104 Correct 753 ms 24532 KB Ok
105 Correct 774 ms 25228 KB Ok
106 Correct 493 ms 23720 KB Ok
107 Correct 670 ms 23368 KB Ok
108 Correct 858 ms 25604 KB Ok
109 Correct 690 ms 25532 KB Ok
110 Execution timed out 2052 ms 38752 KB Time limit exceeded
111 Halted 0 ms 0 KB -