답안 #634022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634022 2022-08-23T17:17:34 Z Tob Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 47688 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;
	
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Ok
2 Correct 6 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 6 ms 9684 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 5 ms 9684 KB Ok
7 Correct 5 ms 9636 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
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Ok
2 Correct 5 ms 9684 KB Ok
3 Correct 5 ms 9656 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 6 ms 9684 KB Ok
6 Correct 12 ms 10068 KB Ok
7 Correct 36 ms 11332 KB Ok
8 Correct 18 ms 10496 KB Ok
9 Correct 44 ms 11580 KB Ok
10 Correct 24 ms 10740 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9684 KB Ok
3 Correct 7 ms 9684 KB Ok
4 Correct 6 ms 9684 KB Ok
5 Correct 5 ms 9740 KB Ok
6 Correct 6 ms 9684 KB Ok
7 Correct 5 ms 9684 KB Ok
8 Correct 5 ms 9700 KB Ok
9 Correct 5 ms 9684 KB Ok
10 Correct 5 ms 9684 KB Ok
11 Correct 5 ms 9684 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 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 515 ms 30132 KB Ok
7 Correct 379 ms 32692 KB Ok
8 Correct 827 ms 34656 KB Ok
9 Correct 598 ms 33072 KB Ok
10 Correct 337 ms 23844 KB Ok
11 Correct 666 ms 35420 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Ok
2 Correct 6 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 6 ms 9684 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 5 ms 9684 KB Ok
7 Correct 5 ms 9636 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 7 ms 9684 KB Ok
16 Correct 6 ms 9684 KB Ok
17 Correct 5 ms 9740 KB Ok
18 Correct 6 ms 9684 KB Ok
19 Correct 5 ms 9684 KB Ok
20 Correct 5 ms 9700 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 9952 KB Ok
25 Correct 13 ms 9996 KB Ok
26 Correct 12 ms 9940 KB Ok
27 Correct 19 ms 9968 KB Ok
28 Correct 10 ms 9864 KB Ok
29 Correct 9 ms 9968 KB Ok
30 Correct 9 ms 9940 KB Ok
31 Correct 9 ms 9944 KB Ok
32 Correct 10 ms 9940 KB Ok
33 Correct 10 ms 9944 KB Ok
34 Correct 18 ms 10276 KB Ok
35 Correct 17 ms 10244 KB Ok
36 Correct 18 ms 10228 KB Ok
37 Correct 19 ms 10252 KB Ok
38 Correct 17 ms 10288 KB Ok
39 Correct 19 ms 10200 KB Ok
40 Correct 19 ms 10196 KB Ok
41 Correct 20 ms 10244 KB Ok
42 Correct 18 ms 10236 KB Ok
43 Correct 18 ms 10212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Ok
2 Correct 6 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 6 ms 9684 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 5 ms 9684 KB Ok
7 Correct 5 ms 9636 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 4 ms 9684 KB Ok
14 Correct 5 ms 9684 KB Ok
15 Correct 5 ms 9656 KB Ok
16 Correct 5 ms 9684 KB Ok
17 Correct 6 ms 9684 KB Ok
18 Correct 12 ms 10068 KB Ok
19 Correct 36 ms 11332 KB Ok
20 Correct 18 ms 10496 KB Ok
21 Correct 44 ms 11580 KB Ok
22 Correct 24 ms 10740 KB Ok
23 Correct 5 ms 9684 KB Ok
24 Correct 5 ms 9684 KB Ok
25 Correct 7 ms 9684 KB Ok
26 Correct 6 ms 9684 KB Ok
27 Correct 5 ms 9740 KB Ok
28 Correct 6 ms 9684 KB Ok
29 Correct 5 ms 9684 KB Ok
30 Correct 5 ms 9700 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 9952 KB Ok
35 Correct 13 ms 9996 KB Ok
36 Correct 12 ms 9940 KB Ok
37 Correct 19 ms 9968 KB Ok
38 Correct 10 ms 9864 KB Ok
39 Correct 9 ms 9968 KB Ok
40 Correct 9 ms 9940 KB Ok
41 Correct 9 ms 9944 KB Ok
42 Correct 10 ms 9940 KB Ok
43 Correct 10 ms 9944 KB Ok
44 Correct 18 ms 10276 KB Ok
45 Correct 17 ms 10244 KB Ok
46 Correct 18 ms 10228 KB Ok
47 Correct 19 ms 10252 KB Ok
48 Correct 17 ms 10288 KB Ok
49 Correct 19 ms 10200 KB Ok
50 Correct 19 ms 10196 KB Ok
51 Correct 20 ms 10244 KB Ok
52 Correct 18 ms 10236 KB Ok
53 Correct 18 ms 10212 KB Ok
54 Correct 252 ms 17104 KB Ok
55 Correct 351 ms 17696 KB Ok
56 Correct 315 ms 17580 KB Ok
57 Correct 202 ms 16392 KB Ok
58 Correct 289 ms 17672 KB Ok
59 Correct 267 ms 16972 KB Ok
60 Correct 213 ms 16432 KB Ok
61 Correct 205 ms 16852 KB Ok
62 Correct 404 ms 18008 KB Ok
63 Correct 237 ms 16796 KB Ok
64 Correct 348 ms 17736 KB Ok
65 Correct 313 ms 17404 KB Ok
66 Correct 227 ms 16988 KB Ok
67 Correct 191 ms 16596 KB Ok
68 Correct 283 ms 17348 KB Ok
69 Correct 1116 ms 26368 KB Ok
70 Correct 976 ms 26820 KB Ok
71 Correct 1053 ms 26480 KB Ok
72 Correct 1060 ms 26244 KB Ok
73 Correct 986 ms 26840 KB Ok
74 Correct 1036 ms 26308 KB Ok
75 Correct 972 ms 26304 KB Ok
76 Correct 1069 ms 26676 KB Ok
77 Correct 1097 ms 26428 KB Ok
78 Correct 1059 ms 26192 KB Ok
79 Correct 1010 ms 26756 KB Ok
80 Correct 1002 ms 26324 KB Ok
81 Correct 1230 ms 26852 KB Ok
82 Correct 1213 ms 26448 KB Ok
83 Correct 1338 ms 26460 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Ok
2 Correct 6 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 6 ms 9684 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 5 ms 9684 KB Ok
7 Correct 5 ms 9636 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 4 ms 9684 KB Ok
14 Correct 5 ms 9684 KB Ok
15 Correct 5 ms 9656 KB Ok
16 Correct 5 ms 9684 KB Ok
17 Correct 6 ms 9684 KB Ok
18 Correct 12 ms 10068 KB Ok
19 Correct 36 ms 11332 KB Ok
20 Correct 18 ms 10496 KB Ok
21 Correct 44 ms 11580 KB Ok
22 Correct 24 ms 10740 KB Ok
23 Correct 5 ms 9684 KB Ok
24 Correct 5 ms 9684 KB Ok
25 Correct 7 ms 9684 KB Ok
26 Correct 6 ms 9684 KB Ok
27 Correct 5 ms 9740 KB Ok
28 Correct 6 ms 9684 KB Ok
29 Correct 5 ms 9684 KB Ok
30 Correct 5 ms 9700 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 4 ms 9684 KB Ok
35 Correct 5 ms 9684 KB Ok
36 Correct 5 ms 9684 KB Ok
37 Correct 5 ms 9684 KB Ok
38 Correct 5 ms 9684 KB Ok
39 Correct 515 ms 30132 KB Ok
40 Correct 379 ms 32692 KB Ok
41 Correct 827 ms 34656 KB Ok
42 Correct 598 ms 33072 KB Ok
43 Correct 337 ms 23844 KB Ok
44 Correct 666 ms 35420 KB Ok
45 Correct 11 ms 9952 KB Ok
46 Correct 13 ms 9996 KB Ok
47 Correct 12 ms 9940 KB Ok
48 Correct 19 ms 9968 KB Ok
49 Correct 10 ms 9864 KB Ok
50 Correct 9 ms 9968 KB Ok
51 Correct 9 ms 9940 KB Ok
52 Correct 9 ms 9944 KB Ok
53 Correct 10 ms 9940 KB Ok
54 Correct 10 ms 9944 KB Ok
55 Correct 18 ms 10276 KB Ok
56 Correct 17 ms 10244 KB Ok
57 Correct 18 ms 10228 KB Ok
58 Correct 19 ms 10252 KB Ok
59 Correct 17 ms 10288 KB Ok
60 Correct 19 ms 10200 KB Ok
61 Correct 19 ms 10196 KB Ok
62 Correct 20 ms 10244 KB Ok
63 Correct 18 ms 10236 KB Ok
64 Correct 18 ms 10212 KB Ok
65 Correct 252 ms 17104 KB Ok
66 Correct 351 ms 17696 KB Ok
67 Correct 315 ms 17580 KB Ok
68 Correct 202 ms 16392 KB Ok
69 Correct 289 ms 17672 KB Ok
70 Correct 267 ms 16972 KB Ok
71 Correct 213 ms 16432 KB Ok
72 Correct 205 ms 16852 KB Ok
73 Correct 404 ms 18008 KB Ok
74 Correct 237 ms 16796 KB Ok
75 Correct 348 ms 17736 KB Ok
76 Correct 313 ms 17404 KB Ok
77 Correct 227 ms 16988 KB Ok
78 Correct 191 ms 16596 KB Ok
79 Correct 283 ms 17348 KB Ok
80 Correct 1116 ms 26368 KB Ok
81 Correct 976 ms 26820 KB Ok
82 Correct 1053 ms 26480 KB Ok
83 Correct 1060 ms 26244 KB Ok
84 Correct 986 ms 26840 KB Ok
85 Correct 1036 ms 26308 KB Ok
86 Correct 972 ms 26304 KB Ok
87 Correct 1069 ms 26676 KB Ok
88 Correct 1097 ms 26428 KB Ok
89 Correct 1059 ms 26192 KB Ok
90 Correct 1010 ms 26756 KB Ok
91 Correct 1002 ms 26324 KB Ok
92 Correct 1230 ms 26852 KB Ok
93 Correct 1213 ms 26448 KB Ok
94 Correct 1338 ms 26460 KB Ok
95 Correct 837 ms 31536 KB Ok
96 Correct 1417 ms 39344 KB Ok
97 Correct 1412 ms 34608 KB Ok
98 Correct 788 ms 34740 KB Ok
99 Correct 1137 ms 33220 KB Ok
100 Correct 1221 ms 34300 KB Ok
101 Correct 1197 ms 36108 KB Ok
102 Correct 1057 ms 33908 KB Ok
103 Correct 1235 ms 36548 KB Ok
104 Correct 1402 ms 37900 KB Ok
105 Correct 1345 ms 38940 KB Ok
106 Correct 920 ms 37336 KB Ok
107 Correct 1096 ms 36840 KB Ok
108 Correct 1436 ms 39244 KB Ok
109 Correct 1096 ms 39472 KB Ok
110 Execution timed out 2090 ms 47688 KB Time limit exceeded
111 Halted 0 ms 0 KB -