답안 #1116150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116150 2024-11-21T09:36:30 Z adiyer Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 80196 KB
#include <bits/stdc++.h>

using namespace std;

typedef int ll;

const int N = 1e6 + 11;

// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll n, m, pos;
ll a[N], was[N], ans[N];

vector < ll > ord, g[N];

bool cyc;

void dfs(ll v){
	was[v] = 1;
	for(ll u : g[v])
		if(!was[u])
			dfs(u);
	ord.push_back(v);
}

bool f(ll sz){
	cyc = 0, ord.clear();
	fill(was, was + sz + 1, 0);
	for(ll i = 0; i <= sz; i++){
		g[i].clear();
		if(i - n >= 0) g[i].push_back(i - n);
		if(i + m <= sz) g[i].push_back(i + m);
	}
	for(ll i = 0; i <= sz; i++)
		if(!was[i])
			dfs(i);
	reverse(ord.begin(), ord.end());
	fill(was, was + sz + 1, 0);
	for(ll v : ord){
		was[v] = 1;
		for(ll u : g[v]){
			if(was[u]){
				return 0;
			}
		}
	}
	return 1;
}

void solve(){
	cin >> n >> m;
	ll l = 0, r = n + m, val = 0;
	while(r - l > 1){
		ll md = (l + r) / 2;
		if(f(md)) l = md;
		else r = md;
	}
	fill(ans, ans + l + 1, 0), f(l);
	for(ll i = 0; i <= l; i++) ans[ord[i]] = i + 1;
	ll p = ans[0];
	cout << l << '\n';
	for(ll i = 1; i <= l; i++) cout << ans[i] - p << ' ', p += ans[i] - p;
	cout << '\n';
}

signed main(){
	ll cs;
	cin >> cs;
	while(cs--){
		solve();
	}
}

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:52:23: warning: unused variable 'val' [-Wunused-variable]
   52 |  ll l = 0, r = n + m, val = 0;
      |                       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 27216 KB Ok
2 Correct 6 ms 27264 KB Ok
3 Correct 7 ms 27276 KB Ok
4 Correct 7 ms 27216 KB Ok
5 Correct 6 ms 27216 KB Ok
6 Correct 6 ms 27216 KB Ok
7 Correct 5 ms 27216 KB Ok
8 Correct 5 ms 27216 KB Ok
9 Correct 6 ms 27216 KB Ok
10 Correct 5 ms 27216 KB Ok
11 Correct 5 ms 27216 KB Ok
12 Correct 6 ms 27384 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 27216 KB Ok
2 Correct 5 ms 27384 KB Ok
3 Correct 5 ms 27216 KB Ok
4 Correct 5 ms 27216 KB Ok
5 Correct 7 ms 27216 KB Ok
6 Correct 8 ms 27504 KB Ok
7 Correct 22 ms 28240 KB Ok
8 Correct 13 ms 27896 KB Ok
9 Correct 27 ms 28372 KB Ok
10 Correct 16 ms 27984 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 27228 KB Ok
2 Correct 5 ms 27384 KB Ok
3 Correct 5 ms 27216 KB Ok
4 Correct 5 ms 27216 KB Ok
5 Correct 6 ms 27388 KB Ok
6 Correct 5 ms 27216 KB Ok
7 Correct 6 ms 27276 KB Ok
8 Correct 6 ms 27216 KB Ok
9 Correct 6 ms 27216 KB Ok
10 Correct 6 ms 27216 KB Ok
11 Correct 5 ms 27216 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 27388 KB Ok
2 Correct 5 ms 27216 KB Ok
3 Correct 5 ms 27228 KB Ok
4 Correct 5 ms 27384 KB Ok
5 Correct 5 ms 27216 KB Ok
6 Correct 196 ms 43680 KB Ok
7 Correct 163 ms 45500 KB Ok
8 Correct 306 ms 47548 KB Ok
9 Correct 254 ms 46748 KB Ok
10 Correct 152 ms 38468 KB Ok
11 Correct 294 ms 48316 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 27216 KB Ok
2 Correct 6 ms 27264 KB Ok
3 Correct 7 ms 27276 KB Ok
4 Correct 7 ms 27216 KB Ok
5 Correct 6 ms 27216 KB Ok
6 Correct 6 ms 27216 KB Ok
7 Correct 5 ms 27216 KB Ok
8 Correct 5 ms 27216 KB Ok
9 Correct 6 ms 27216 KB Ok
10 Correct 5 ms 27216 KB Ok
11 Correct 5 ms 27216 KB Ok
12 Correct 6 ms 27384 KB Ok
13 Correct 5 ms 27228 KB Ok
14 Correct 5 ms 27384 KB Ok
15 Correct 5 ms 27216 KB Ok
16 Correct 5 ms 27216 KB Ok
17 Correct 6 ms 27388 KB Ok
18 Correct 5 ms 27216 KB Ok
19 Correct 6 ms 27276 KB Ok
20 Correct 6 ms 27216 KB Ok
21 Correct 6 ms 27216 KB Ok
22 Correct 6 ms 27216 KB Ok
23 Correct 5 ms 27216 KB Ok
24 Correct 8 ms 27216 KB Ok
25 Correct 9 ms 27472 KB Ok
26 Correct 9 ms 27216 KB Ok
27 Correct 8 ms 27216 KB Ok
28 Correct 8 ms 27216 KB Ok
29 Correct 7 ms 27216 KB Ok
30 Correct 8 ms 27216 KB Ok
31 Correct 7 ms 27276 KB Ok
32 Correct 8 ms 27440 KB Ok
33 Correct 7 ms 27216 KB Ok
34 Correct 13 ms 27728 KB Ok
35 Correct 13 ms 27528 KB Ok
36 Correct 15 ms 27728 KB Ok
37 Correct 12 ms 27900 KB Ok
38 Correct 13 ms 27728 KB Ok
39 Correct 12 ms 27728 KB Ok
40 Correct 13 ms 27728 KB Ok
41 Correct 13 ms 27728 KB Ok
42 Correct 13 ms 27780 KB Ok
43 Correct 13 ms 27604 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 27216 KB Ok
2 Correct 6 ms 27264 KB Ok
3 Correct 7 ms 27276 KB Ok
4 Correct 7 ms 27216 KB Ok
5 Correct 6 ms 27216 KB Ok
6 Correct 6 ms 27216 KB Ok
7 Correct 5 ms 27216 KB Ok
8 Correct 5 ms 27216 KB Ok
9 Correct 6 ms 27216 KB Ok
10 Correct 5 ms 27216 KB Ok
11 Correct 5 ms 27216 KB Ok
12 Correct 6 ms 27384 KB Ok
13 Correct 6 ms 27216 KB Ok
14 Correct 5 ms 27384 KB Ok
15 Correct 5 ms 27216 KB Ok
16 Correct 5 ms 27216 KB Ok
17 Correct 7 ms 27216 KB Ok
18 Correct 8 ms 27504 KB Ok
19 Correct 22 ms 28240 KB Ok
20 Correct 13 ms 27896 KB Ok
21 Correct 27 ms 28372 KB Ok
22 Correct 16 ms 27984 KB Ok
23 Correct 5 ms 27228 KB Ok
24 Correct 5 ms 27384 KB Ok
25 Correct 5 ms 27216 KB Ok
26 Correct 5 ms 27216 KB Ok
27 Correct 6 ms 27388 KB Ok
28 Correct 5 ms 27216 KB Ok
29 Correct 6 ms 27276 KB Ok
30 Correct 6 ms 27216 KB Ok
31 Correct 6 ms 27216 KB Ok
32 Correct 6 ms 27216 KB Ok
33 Correct 5 ms 27216 KB Ok
34 Correct 8 ms 27216 KB Ok
35 Correct 9 ms 27472 KB Ok
36 Correct 9 ms 27216 KB Ok
37 Correct 8 ms 27216 KB Ok
38 Correct 8 ms 27216 KB Ok
39 Correct 7 ms 27216 KB Ok
40 Correct 8 ms 27216 KB Ok
41 Correct 7 ms 27276 KB Ok
42 Correct 8 ms 27440 KB Ok
43 Correct 7 ms 27216 KB Ok
44 Correct 13 ms 27728 KB Ok
45 Correct 13 ms 27528 KB Ok
46 Correct 15 ms 27728 KB Ok
47 Correct 12 ms 27900 KB Ok
48 Correct 13 ms 27728 KB Ok
49 Correct 12 ms 27728 KB Ok
50 Correct 13 ms 27728 KB Ok
51 Correct 13 ms 27728 KB Ok
52 Correct 13 ms 27780 KB Ok
53 Correct 13 ms 27604 KB Ok
54 Correct 144 ms 32456 KB Ok
55 Correct 164 ms 32964 KB Ok
56 Correct 157 ms 32960 KB Ok
57 Correct 121 ms 31936 KB Ok
58 Correct 164 ms 32868 KB Ok
59 Correct 163 ms 32452 KB Ok
60 Correct 137 ms 31936 KB Ok
61 Correct 121 ms 32448 KB Ok
62 Correct 195 ms 33216 KB Ok
63 Correct 145 ms 32192 KB Ok
64 Correct 175 ms 32960 KB Ok
65 Correct 160 ms 32964 KB Ok
66 Correct 132 ms 32448 KB Ok
67 Correct 127 ms 32192 KB Ok
68 Correct 168 ms 32824 KB Ok
69 Correct 557 ms 41432 KB Ok
70 Correct 532 ms 41964 KB Ok
71 Correct 508 ms 41648 KB Ok
72 Correct 485 ms 41448 KB Ok
73 Correct 557 ms 41664 KB Ok
74 Correct 527 ms 41408 KB Ok
75 Correct 518 ms 41520 KB Ok
76 Correct 547 ms 41508 KB Ok
77 Correct 527 ms 41324 KB Ok
78 Correct 550 ms 41504 KB Ok
79 Correct 507 ms 41920 KB Ok
80 Correct 483 ms 41408 KB Ok
81 Correct 511 ms 41920 KB Ok
82 Correct 584 ms 41588 KB Ok
83 Correct 518 ms 41664 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 27216 KB Ok
2 Correct 6 ms 27264 KB Ok
3 Correct 7 ms 27276 KB Ok
4 Correct 7 ms 27216 KB Ok
5 Correct 6 ms 27216 KB Ok
6 Correct 6 ms 27216 KB Ok
7 Correct 5 ms 27216 KB Ok
8 Correct 5 ms 27216 KB Ok
9 Correct 6 ms 27216 KB Ok
10 Correct 5 ms 27216 KB Ok
11 Correct 5 ms 27216 KB Ok
12 Correct 6 ms 27384 KB Ok
13 Correct 6 ms 27216 KB Ok
14 Correct 5 ms 27384 KB Ok
15 Correct 5 ms 27216 KB Ok
16 Correct 5 ms 27216 KB Ok
17 Correct 7 ms 27216 KB Ok
18 Correct 8 ms 27504 KB Ok
19 Correct 22 ms 28240 KB Ok
20 Correct 13 ms 27896 KB Ok
21 Correct 27 ms 28372 KB Ok
22 Correct 16 ms 27984 KB Ok
23 Correct 5 ms 27228 KB Ok
24 Correct 5 ms 27384 KB Ok
25 Correct 5 ms 27216 KB Ok
26 Correct 5 ms 27216 KB Ok
27 Correct 6 ms 27388 KB Ok
28 Correct 5 ms 27216 KB Ok
29 Correct 6 ms 27276 KB Ok
30 Correct 6 ms 27216 KB Ok
31 Correct 6 ms 27216 KB Ok
32 Correct 6 ms 27216 KB Ok
33 Correct 5 ms 27216 KB Ok
34 Correct 5 ms 27388 KB Ok
35 Correct 5 ms 27216 KB Ok
36 Correct 5 ms 27228 KB Ok
37 Correct 5 ms 27384 KB Ok
38 Correct 5 ms 27216 KB Ok
39 Correct 196 ms 43680 KB Ok
40 Correct 163 ms 45500 KB Ok
41 Correct 306 ms 47548 KB Ok
42 Correct 254 ms 46748 KB Ok
43 Correct 152 ms 38468 KB Ok
44 Correct 294 ms 48316 KB Ok
45 Correct 8 ms 27216 KB Ok
46 Correct 9 ms 27472 KB Ok
47 Correct 9 ms 27216 KB Ok
48 Correct 8 ms 27216 KB Ok
49 Correct 8 ms 27216 KB Ok
50 Correct 7 ms 27216 KB Ok
51 Correct 8 ms 27216 KB Ok
52 Correct 7 ms 27276 KB Ok
53 Correct 8 ms 27440 KB Ok
54 Correct 7 ms 27216 KB Ok
55 Correct 13 ms 27728 KB Ok
56 Correct 13 ms 27528 KB Ok
57 Correct 15 ms 27728 KB Ok
58 Correct 12 ms 27900 KB Ok
59 Correct 13 ms 27728 KB Ok
60 Correct 12 ms 27728 KB Ok
61 Correct 13 ms 27728 KB Ok
62 Correct 13 ms 27728 KB Ok
63 Correct 13 ms 27780 KB Ok
64 Correct 13 ms 27604 KB Ok
65 Correct 144 ms 32456 KB Ok
66 Correct 164 ms 32964 KB Ok
67 Correct 157 ms 32960 KB Ok
68 Correct 121 ms 31936 KB Ok
69 Correct 164 ms 32868 KB Ok
70 Correct 163 ms 32452 KB Ok
71 Correct 137 ms 31936 KB Ok
72 Correct 121 ms 32448 KB Ok
73 Correct 195 ms 33216 KB Ok
74 Correct 145 ms 32192 KB Ok
75 Correct 175 ms 32960 KB Ok
76 Correct 160 ms 32964 KB Ok
77 Correct 132 ms 32448 KB Ok
78 Correct 127 ms 32192 KB Ok
79 Correct 168 ms 32824 KB Ok
80 Correct 557 ms 41432 KB Ok
81 Correct 532 ms 41964 KB Ok
82 Correct 508 ms 41648 KB Ok
83 Correct 485 ms 41448 KB Ok
84 Correct 557 ms 41664 KB Ok
85 Correct 527 ms 41408 KB Ok
86 Correct 518 ms 41520 KB Ok
87 Correct 547 ms 41508 KB Ok
88 Correct 527 ms 41324 KB Ok
89 Correct 550 ms 41504 KB Ok
90 Correct 507 ms 41920 KB Ok
91 Correct 483 ms 41408 KB Ok
92 Correct 511 ms 41920 KB Ok
93 Correct 584 ms 41588 KB Ok
94 Correct 518 ms 41664 KB Ok
95 Correct 368 ms 41368 KB Ok
96 Correct 618 ms 51128 KB Ok
97 Correct 542 ms 46008 KB Ok
98 Correct 395 ms 44984 KB Ok
99 Correct 486 ms 44860 KB Ok
100 Correct 521 ms 45496 KB Ok
101 Correct 487 ms 46776 KB Ok
102 Correct 477 ms 45736 KB Ok
103 Correct 512 ms 46780 KB Ok
104 Correct 594 ms 48060 KB Ok
105 Correct 581 ms 50724 KB Ok
106 Correct 475 ms 49440 KB Ok
107 Correct 555 ms 47316 KB Ok
108 Correct 673 ms 50872 KB Ok
109 Correct 509 ms 50616 KB Ok
110 Execution timed out 2045 ms 80196 KB Time limit exceeded
111 Halted 0 ms 0 KB -