Submission #634059

# Submission time Handle Problem Language Result Execution time Memory
634059 2022-08-23T18:17:00 Z Tob Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 47660 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;
vector <int> adj[maxn];
ll val[maxn], bio[maxn], ps[maxn];

void dfs(int x) {
	bio[x] = 1;
	for (auto it : adj[x]) {
		if (bio[it] == 2) continue;
		if (bio[it] == 1) {
			ndag = 1;
			continue;
		}
		dfs(it);
	}
	bio[x] = 2;
	v.pb(x);
}

bool stask(int ma) {
	for (int i = 0; i <= ma; i++) {
		adj[i].clear();
	}
	v.clear();
	for (int i = 0; i <= ma; i++) bio[i] = 0;
	ndag = 0;
	
	for (int i = 0; i <= ma; i++) {
		if (i + m <= ma) adj[i].pb(i+m);
		if (i + n <= ma) adj[i+n].pb(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;
	for (int i = 0; i <= hi; i++)  adj[i].reserve(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 5 ms 9640 KB Ok
2 Correct 5 ms 9744 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 5 ms 9692 KB Ok
6 Correct 6 ms 9812 KB Ok
7 Correct 6 ms 9684 KB Ok
8 Correct 5 ms 9684 KB Ok
9 Correct 5 ms 9684 KB Ok
10 Correct 6 ms 9684 KB Ok
11 Correct 5 ms 9684 KB Ok
12 Correct 5 ms 9684 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9684 KB Ok
3 Correct 6 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 6 ms 9656 KB Ok
6 Correct 10 ms 10044 KB Ok
7 Correct 35 ms 11484 KB Ok
8 Correct 17 ms 10552 KB Ok
9 Correct 43 ms 11860 KB Ok
10 Correct 25 ms 10860 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9656 KB Ok
2 Correct 5 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 5 ms 9684 KB Ok
7 Correct 5 ms 9684 KB Ok
8 Correct 5 ms 9684 KB Ok
9 Correct 5 ms 9684 KB Ok
10 Correct 5 ms 9684 KB Ok
11 Correct 5 ms 9684 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9684 KB Ok
3 Correct 6 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 458 ms 30208 KB Ok
7 Correct 362 ms 32700 KB Ok
8 Correct 732 ms 34776 KB Ok
9 Correct 542 ms 33112 KB Ok
10 Correct 303 ms 23828 KB Ok
11 Correct 584 ms 35368 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9640 KB Ok
2 Correct 5 ms 9744 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 5 ms 9692 KB Ok
6 Correct 6 ms 9812 KB Ok
7 Correct 6 ms 9684 KB Ok
8 Correct 5 ms 9684 KB Ok
9 Correct 5 ms 9684 KB Ok
10 Correct 6 ms 9684 KB Ok
11 Correct 5 ms 9684 KB Ok
12 Correct 5 ms 9684 KB Ok
13 Correct 5 ms 9656 KB Ok
14 Correct 5 ms 9684 KB Ok
15 Correct 5 ms 9684 KB Ok
16 Correct 5 ms 9684 KB Ok
17 Correct 5 ms 9684 KB Ok
18 Correct 5 ms 9684 KB Ok
19 Correct 5 ms 9684 KB Ok
20 Correct 5 ms 9684 KB Ok
21 Correct 5 ms 9684 KB Ok
22 Correct 5 ms 9684 KB Ok
23 Correct 5 ms 9684 KB Ok
24 Correct 11 ms 9940 KB Ok
25 Correct 11 ms 9940 KB Ok
26 Correct 10 ms 9940 KB Ok
27 Correct 9 ms 9956 KB Ok
28 Correct 9 ms 9960 KB Ok
29 Correct 8 ms 9940 KB Ok
30 Correct 10 ms 9956 KB Ok
31 Correct 10 ms 9940 KB Ok
32 Correct 10 ms 9992 KB Ok
33 Correct 10 ms 10004 KB Ok
34 Correct 18 ms 10320 KB Ok
35 Correct 18 ms 10264 KB Ok
36 Correct 18 ms 10320 KB Ok
37 Correct 17 ms 10312 KB Ok
38 Correct 17 ms 10196 KB Ok
39 Correct 17 ms 10296 KB Ok
40 Correct 18 ms 10196 KB Ok
41 Correct 17 ms 10316 KB Ok
42 Correct 19 ms 10284 KB Ok
43 Correct 18 ms 10292 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9640 KB Ok
2 Correct 5 ms 9744 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 5 ms 9692 KB Ok
6 Correct 6 ms 9812 KB Ok
7 Correct 6 ms 9684 KB Ok
8 Correct 5 ms 9684 KB Ok
9 Correct 5 ms 9684 KB Ok
10 Correct 6 ms 9684 KB Ok
11 Correct 5 ms 9684 KB Ok
12 Correct 5 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 5 ms 9684 KB Ok
15 Correct 6 ms 9684 KB Ok
16 Correct 5 ms 9684 KB Ok
17 Correct 6 ms 9656 KB Ok
18 Correct 10 ms 10044 KB Ok
19 Correct 35 ms 11484 KB Ok
20 Correct 17 ms 10552 KB Ok
21 Correct 43 ms 11860 KB Ok
22 Correct 25 ms 10860 KB Ok
23 Correct 5 ms 9656 KB Ok
24 Correct 5 ms 9684 KB Ok
25 Correct 5 ms 9684 KB Ok
26 Correct 5 ms 9684 KB Ok
27 Correct 5 ms 9684 KB Ok
28 Correct 5 ms 9684 KB Ok
29 Correct 5 ms 9684 KB Ok
30 Correct 5 ms 9684 KB Ok
31 Correct 5 ms 9684 KB Ok
32 Correct 5 ms 9684 KB Ok
33 Correct 5 ms 9684 KB Ok
34 Correct 11 ms 9940 KB Ok
35 Correct 11 ms 9940 KB Ok
36 Correct 10 ms 9940 KB Ok
37 Correct 9 ms 9956 KB Ok
38 Correct 9 ms 9960 KB Ok
39 Correct 8 ms 9940 KB Ok
40 Correct 10 ms 9956 KB Ok
41 Correct 10 ms 9940 KB Ok
42 Correct 10 ms 9992 KB Ok
43 Correct 10 ms 10004 KB Ok
44 Correct 18 ms 10320 KB Ok
45 Correct 18 ms 10264 KB Ok
46 Correct 18 ms 10320 KB Ok
47 Correct 17 ms 10312 KB Ok
48 Correct 17 ms 10196 KB Ok
49 Correct 17 ms 10296 KB Ok
50 Correct 18 ms 10196 KB Ok
51 Correct 17 ms 10316 KB Ok
52 Correct 19 ms 10284 KB Ok
53 Correct 18 ms 10292 KB Ok
54 Correct 245 ms 17380 KB Ok
55 Correct 325 ms 17840 KB Ok
56 Correct 285 ms 17812 KB Ok
57 Correct 189 ms 16756 KB Ok
58 Correct 284 ms 17736 KB Ok
59 Correct 246 ms 17476 KB Ok
60 Correct 216 ms 16972 KB Ok
61 Correct 195 ms 17024 KB Ok
62 Correct 359 ms 18180 KB Ok
63 Correct 246 ms 17100 KB Ok
64 Correct 318 ms 17992 KB Ok
65 Correct 294 ms 17780 KB Ok
66 Correct 230 ms 17280 KB Ok
67 Correct 189 ms 16944 KB Ok
68 Correct 269 ms 17608 KB Ok
69 Correct 1165 ms 26612 KB Ok
70 Correct 1234 ms 27032 KB Ok
71 Correct 1115 ms 26532 KB Ok
72 Correct 974 ms 26424 KB Ok
73 Correct 1252 ms 26880 KB Ok
74 Correct 1050 ms 26388 KB Ok
75 Correct 996 ms 26436 KB Ok
76 Correct 1049 ms 26588 KB Ok
77 Correct 1054 ms 26420 KB Ok
78 Correct 1128 ms 26436 KB Ok
79 Correct 1132 ms 26880 KB Ok
80 Correct 1086 ms 26496 KB Ok
81 Correct 965 ms 26904 KB Ok
82 Correct 1037 ms 26628 KB Ok
83 Correct 1018 ms 26592 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9640 KB Ok
2 Correct 5 ms 9744 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 5 ms 9692 KB Ok
6 Correct 6 ms 9812 KB Ok
7 Correct 6 ms 9684 KB Ok
8 Correct 5 ms 9684 KB Ok
9 Correct 5 ms 9684 KB Ok
10 Correct 6 ms 9684 KB Ok
11 Correct 5 ms 9684 KB Ok
12 Correct 5 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 5 ms 9684 KB Ok
15 Correct 6 ms 9684 KB Ok
16 Correct 5 ms 9684 KB Ok
17 Correct 6 ms 9656 KB Ok
18 Correct 10 ms 10044 KB Ok
19 Correct 35 ms 11484 KB Ok
20 Correct 17 ms 10552 KB Ok
21 Correct 43 ms 11860 KB Ok
22 Correct 25 ms 10860 KB Ok
23 Correct 5 ms 9656 KB Ok
24 Correct 5 ms 9684 KB Ok
25 Correct 5 ms 9684 KB Ok
26 Correct 5 ms 9684 KB Ok
27 Correct 5 ms 9684 KB Ok
28 Correct 5 ms 9684 KB Ok
29 Correct 5 ms 9684 KB Ok
30 Correct 5 ms 9684 KB Ok
31 Correct 5 ms 9684 KB Ok
32 Correct 5 ms 9684 KB Ok
33 Correct 5 ms 9684 KB Ok
34 Correct 5 ms 9684 KB Ok
35 Correct 5 ms 9684 KB Ok
36 Correct 6 ms 9684 KB Ok
37 Correct 5 ms 9684 KB Ok
38 Correct 5 ms 9684 KB Ok
39 Correct 458 ms 30208 KB Ok
40 Correct 362 ms 32700 KB Ok
41 Correct 732 ms 34776 KB Ok
42 Correct 542 ms 33112 KB Ok
43 Correct 303 ms 23828 KB Ok
44 Correct 584 ms 35368 KB Ok
45 Correct 11 ms 9940 KB Ok
46 Correct 11 ms 9940 KB Ok
47 Correct 10 ms 9940 KB Ok
48 Correct 9 ms 9956 KB Ok
49 Correct 9 ms 9960 KB Ok
50 Correct 8 ms 9940 KB Ok
51 Correct 10 ms 9956 KB Ok
52 Correct 10 ms 9940 KB Ok
53 Correct 10 ms 9992 KB Ok
54 Correct 10 ms 10004 KB Ok
55 Correct 18 ms 10320 KB Ok
56 Correct 18 ms 10264 KB Ok
57 Correct 18 ms 10320 KB Ok
58 Correct 17 ms 10312 KB Ok
59 Correct 17 ms 10196 KB Ok
60 Correct 17 ms 10296 KB Ok
61 Correct 18 ms 10196 KB Ok
62 Correct 17 ms 10316 KB Ok
63 Correct 19 ms 10284 KB Ok
64 Correct 18 ms 10292 KB Ok
65 Correct 245 ms 17380 KB Ok
66 Correct 325 ms 17840 KB Ok
67 Correct 285 ms 17812 KB Ok
68 Correct 189 ms 16756 KB Ok
69 Correct 284 ms 17736 KB Ok
70 Correct 246 ms 17476 KB Ok
71 Correct 216 ms 16972 KB Ok
72 Correct 195 ms 17024 KB Ok
73 Correct 359 ms 18180 KB Ok
74 Correct 246 ms 17100 KB Ok
75 Correct 318 ms 17992 KB Ok
76 Correct 294 ms 17780 KB Ok
77 Correct 230 ms 17280 KB Ok
78 Correct 189 ms 16944 KB Ok
79 Correct 269 ms 17608 KB Ok
80 Correct 1165 ms 26612 KB Ok
81 Correct 1234 ms 27032 KB Ok
82 Correct 1115 ms 26532 KB Ok
83 Correct 974 ms 26424 KB Ok
84 Correct 1252 ms 26880 KB Ok
85 Correct 1050 ms 26388 KB Ok
86 Correct 996 ms 26436 KB Ok
87 Correct 1049 ms 26588 KB Ok
88 Correct 1054 ms 26420 KB Ok
89 Correct 1128 ms 26436 KB Ok
90 Correct 1132 ms 26880 KB Ok
91 Correct 1086 ms 26496 KB Ok
92 Correct 965 ms 26904 KB Ok
93 Correct 1037 ms 26628 KB Ok
94 Correct 1018 ms 26592 KB Ok
95 Correct 747 ms 34676 KB Ok
96 Correct 1237 ms 40280 KB Ok
97 Correct 1183 ms 37800 KB Ok
98 Correct 689 ms 36252 KB Ok
99 Correct 1002 ms 36032 KB Ok
100 Correct 1060 ms 37580 KB Ok
101 Correct 991 ms 38152 KB Ok
102 Correct 890 ms 36816 KB Ok
103 Correct 1008 ms 38360 KB Ok
104 Correct 1161 ms 39580 KB Ok
105 Correct 1229 ms 39772 KB Ok
106 Correct 810 ms 37776 KB Ok
107 Correct 1043 ms 38388 KB Ok
108 Correct 1445 ms 40284 KB Ok
109 Correct 1118 ms 39828 KB Ok
110 Execution timed out 2091 ms 47660 KB Time limit exceeded
111 Halted 0 ms 0 KB -