Submission #493325

# Submission time Handle Problem Language Result Execution time Memory
493325 2021-12-11T01:58:32 Z hollwo_pelw Nice sequence (IZhO18_sequence) C++17
100 / 100
377 ms 31252 KB
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
	if (fopen(filein.c_str(), "r")){
		freopen(filein.c_str(), "r", stdin);
		freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
		freopen(fileerr.c_str(), "w", stderr);
#endif
	}
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}

void Hollwo_Pelw();

signed main(){
#ifdef hollwo_pelw_local
	FAST_IO("input.inp", "output.out", "error.err");
	auto start = chrono::steady_clock::now();
#else
	FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out");
#endif
	int testcases = 1;
	cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = chrono::steady_clock::now();
	cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
	return 0;
}

const int N = 4e5 + 5;

int n, m, sz, pre[N], deg[N];

// pre[i] - pre[i - m] > 0
// pre[i - n] - pre[i] > 0 

void Hollwo_Pelw() {
	cin >> n >> m;
	sz = n + m - __gcd(n, m);
	
	fill(deg, deg + sz, 0);

	for (int i = 0; i < sz; i++)
		for (auto j : {i - m, i + n}) 
			if (0 <= j && j < sz) deg[j] ++;

	queue<int> q;

	for (int i = 0; i < sz; i++)
		if (!deg[i]) q.push(i);

	int cur = N;

	while (!q.empty()) {
		int i = q.front(); q.pop();

		pre[i] = cur --;

		for (auto j : {i - m, i + n}) 
			if (0 <= j && j < sz) 
				if (!(--deg[j])) q.push(j);
	}

	cout << sz - 1 << '\n';
	for (int i = 1; i < sz; i++)
		cout << pre[i] - pre[i - 1] << ' ';
	cout << '\n';
}

Compilation message

sequence.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
sequence.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 1 ms 332 KB Ok
5 Correct 0 ms 332 KB Ok
6 Correct 1 ms 332 KB Ok
7 Correct 0 ms 332 KB Ok
8 Correct 1 ms 332 KB Ok
9 Correct 1 ms 332 KB Ok
10 Correct 0 ms 332 KB Ok
11 Correct 0 ms 332 KB Ok
12 Correct 1 ms 332 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 0 ms 332 KB Ok
5 Correct 1 ms 332 KB Ok
6 Correct 2 ms 332 KB Ok
7 Correct 8 ms 716 KB Ok
8 Correct 9 ms 460 KB Ok
9 Correct 10 ms 716 KB Ok
10 Correct 8 ms 588 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 1 ms 332 KB Ok
5 Correct 0 ms 332 KB Ok
6 Correct 0 ms 332 KB Ok
7 Correct 0 ms 332 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 0 ms 332 KB Ok
10 Correct 0 ms 332 KB Ok
11 Correct 1 ms 332 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 1 ms 332 KB Ok
5 Correct 1 ms 332 KB Ok
6 Correct 74 ms 4500 KB Ok
7 Correct 58 ms 3924 KB Ok
8 Correct 115 ms 6100 KB Ok
9 Correct 98 ms 6388 KB Ok
10 Correct 56 ms 2868 KB Ok
11 Correct 89 ms 5548 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 1 ms 332 KB Ok
5 Correct 0 ms 332 KB Ok
6 Correct 1 ms 332 KB Ok
7 Correct 0 ms 332 KB Ok
8 Correct 1 ms 332 KB Ok
9 Correct 1 ms 332 KB Ok
10 Correct 0 ms 332 KB Ok
11 Correct 0 ms 332 KB Ok
12 Correct 1 ms 332 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 332 KB Ok
15 Correct 0 ms 332 KB Ok
16 Correct 1 ms 332 KB Ok
17 Correct 0 ms 332 KB Ok
18 Correct 0 ms 332 KB Ok
19 Correct 0 ms 332 KB Ok
20 Correct 0 ms 204 KB Ok
21 Correct 0 ms 332 KB Ok
22 Correct 0 ms 332 KB Ok
23 Correct 1 ms 332 KB Ok
24 Correct 2 ms 332 KB Ok
25 Correct 2 ms 332 KB Ok
26 Correct 2 ms 332 KB Ok
27 Correct 2 ms 332 KB Ok
28 Correct 2 ms 332 KB Ok
29 Correct 2 ms 332 KB Ok
30 Correct 3 ms 332 KB Ok
31 Correct 2 ms 332 KB Ok
32 Correct 2 ms 332 KB Ok
33 Correct 2 ms 332 KB Ok
34 Correct 4 ms 460 KB Ok
35 Correct 3 ms 460 KB Ok
36 Correct 3 ms 460 KB Ok
37 Correct 3 ms 460 KB Ok
38 Correct 3 ms 460 KB Ok
39 Correct 4 ms 476 KB Ok
40 Correct 5 ms 460 KB Ok
41 Correct 3 ms 452 KB Ok
42 Correct 4 ms 460 KB Ok
43 Correct 4 ms 460 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 1 ms 332 KB Ok
5 Correct 0 ms 332 KB Ok
6 Correct 1 ms 332 KB Ok
7 Correct 0 ms 332 KB Ok
8 Correct 1 ms 332 KB Ok
9 Correct 1 ms 332 KB Ok
10 Correct 0 ms 332 KB Ok
11 Correct 0 ms 332 KB Ok
12 Correct 1 ms 332 KB Ok
13 Correct 0 ms 332 KB Ok
14 Correct 0 ms 332 KB Ok
15 Correct 0 ms 332 KB Ok
16 Correct 0 ms 332 KB Ok
17 Correct 1 ms 332 KB Ok
18 Correct 2 ms 332 KB Ok
19 Correct 8 ms 716 KB Ok
20 Correct 9 ms 460 KB Ok
21 Correct 10 ms 716 KB Ok
22 Correct 8 ms 588 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 332 KB Ok
25 Correct 0 ms 332 KB Ok
26 Correct 1 ms 332 KB Ok
27 Correct 0 ms 332 KB Ok
28 Correct 0 ms 332 KB Ok
29 Correct 0 ms 332 KB Ok
30 Correct 0 ms 204 KB Ok
31 Correct 0 ms 332 KB Ok
32 Correct 0 ms 332 KB Ok
33 Correct 1 ms 332 KB Ok
34 Correct 2 ms 332 KB Ok
35 Correct 2 ms 332 KB Ok
36 Correct 2 ms 332 KB Ok
37 Correct 2 ms 332 KB Ok
38 Correct 2 ms 332 KB Ok
39 Correct 2 ms 332 KB Ok
40 Correct 3 ms 332 KB Ok
41 Correct 2 ms 332 KB Ok
42 Correct 2 ms 332 KB Ok
43 Correct 2 ms 332 KB Ok
44 Correct 4 ms 460 KB Ok
45 Correct 3 ms 460 KB Ok
46 Correct 3 ms 460 KB Ok
47 Correct 3 ms 460 KB Ok
48 Correct 3 ms 460 KB Ok
49 Correct 4 ms 476 KB Ok
50 Correct 5 ms 460 KB Ok
51 Correct 3 ms 452 KB Ok
52 Correct 4 ms 460 KB Ok
53 Correct 4 ms 460 KB Ok
54 Correct 55 ms 3176 KB Ok
55 Correct 64 ms 3408 KB Ok
56 Correct 76 ms 3520 KB Ok
57 Correct 47 ms 2904 KB Ok
58 Correct 58 ms 3232 KB Ok
59 Correct 64 ms 3216 KB Ok
60 Correct 49 ms 2884 KB Ok
61 Correct 51 ms 2960 KB Ok
62 Correct 69 ms 3400 KB Ok
63 Correct 52 ms 2972 KB Ok
64 Correct 60 ms 3348 KB Ok
65 Correct 64 ms 3260 KB Ok
66 Correct 53 ms 3116 KB Ok
67 Correct 49 ms 2780 KB Ok
68 Correct 63 ms 3244 KB Ok
69 Correct 87 ms 6500 KB Ok
70 Correct 114 ms 7608 KB Ok
71 Correct 99 ms 5988 KB Ok
72 Correct 100 ms 6816 KB Ok
73 Correct 90 ms 6448 KB Ok
74 Correct 94 ms 5700 KB Ok
75 Correct 93 ms 5664 KB Ok
76 Correct 95 ms 7376 KB Ok
77 Correct 88 ms 5308 KB Ok
78 Correct 88 ms 7076 KB Ok
79 Correct 89 ms 6652 KB Ok
80 Correct 87 ms 6476 KB Ok
81 Correct 98 ms 6960 KB Ok
82 Correct 90 ms 6596 KB Ok
83 Correct 100 ms 5752 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Ok
2 Correct 0 ms 332 KB Ok
3 Correct 0 ms 332 KB Ok
4 Correct 1 ms 332 KB Ok
5 Correct 0 ms 332 KB Ok
6 Correct 1 ms 332 KB Ok
7 Correct 0 ms 332 KB Ok
8 Correct 1 ms 332 KB Ok
9 Correct 1 ms 332 KB Ok
10 Correct 0 ms 332 KB Ok
11 Correct 0 ms 332 KB Ok
12 Correct 1 ms 332 KB Ok
13 Correct 0 ms 332 KB Ok
14 Correct 0 ms 332 KB Ok
15 Correct 0 ms 332 KB Ok
16 Correct 0 ms 332 KB Ok
17 Correct 1 ms 332 KB Ok
18 Correct 2 ms 332 KB Ok
19 Correct 8 ms 716 KB Ok
20 Correct 9 ms 460 KB Ok
21 Correct 10 ms 716 KB Ok
22 Correct 8 ms 588 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 332 KB Ok
25 Correct 0 ms 332 KB Ok
26 Correct 1 ms 332 KB Ok
27 Correct 0 ms 332 KB Ok
28 Correct 0 ms 332 KB Ok
29 Correct 0 ms 332 KB Ok
30 Correct 0 ms 204 KB Ok
31 Correct 0 ms 332 KB Ok
32 Correct 0 ms 332 KB Ok
33 Correct 1 ms 332 KB Ok
34 Correct 1 ms 332 KB Ok
35 Correct 0 ms 332 KB Ok
36 Correct 0 ms 332 KB Ok
37 Correct 1 ms 332 KB Ok
38 Correct 1 ms 332 KB Ok
39 Correct 74 ms 4500 KB Ok
40 Correct 58 ms 3924 KB Ok
41 Correct 115 ms 6100 KB Ok
42 Correct 98 ms 6388 KB Ok
43 Correct 56 ms 2868 KB Ok
44 Correct 89 ms 5548 KB Ok
45 Correct 2 ms 332 KB Ok
46 Correct 2 ms 332 KB Ok
47 Correct 2 ms 332 KB Ok
48 Correct 2 ms 332 KB Ok
49 Correct 2 ms 332 KB Ok
50 Correct 2 ms 332 KB Ok
51 Correct 3 ms 332 KB Ok
52 Correct 2 ms 332 KB Ok
53 Correct 2 ms 332 KB Ok
54 Correct 2 ms 332 KB Ok
55 Correct 4 ms 460 KB Ok
56 Correct 3 ms 460 KB Ok
57 Correct 3 ms 460 KB Ok
58 Correct 3 ms 460 KB Ok
59 Correct 3 ms 460 KB Ok
60 Correct 4 ms 476 KB Ok
61 Correct 5 ms 460 KB Ok
62 Correct 3 ms 452 KB Ok
63 Correct 4 ms 460 KB Ok
64 Correct 4 ms 460 KB Ok
65 Correct 55 ms 3176 KB Ok
66 Correct 64 ms 3408 KB Ok
67 Correct 76 ms 3520 KB Ok
68 Correct 47 ms 2904 KB Ok
69 Correct 58 ms 3232 KB Ok
70 Correct 64 ms 3216 KB Ok
71 Correct 49 ms 2884 KB Ok
72 Correct 51 ms 2960 KB Ok
73 Correct 69 ms 3400 KB Ok
74 Correct 52 ms 2972 KB Ok
75 Correct 60 ms 3348 KB Ok
76 Correct 64 ms 3260 KB Ok
77 Correct 53 ms 3116 KB Ok
78 Correct 49 ms 2780 KB Ok
79 Correct 63 ms 3244 KB Ok
80 Correct 87 ms 6500 KB Ok
81 Correct 114 ms 7608 KB Ok
82 Correct 99 ms 5988 KB Ok
83 Correct 100 ms 6816 KB Ok
84 Correct 90 ms 6448 KB Ok
85 Correct 94 ms 5700 KB Ok
86 Correct 93 ms 5664 KB Ok
87 Correct 95 ms 7376 KB Ok
88 Correct 88 ms 5308 KB Ok
89 Correct 88 ms 7076 KB Ok
90 Correct 89 ms 6652 KB Ok
91 Correct 87 ms 6476 KB Ok
92 Correct 98 ms 6960 KB Ok
93 Correct 90 ms 6596 KB Ok
94 Correct 100 ms 5752 KB Ok
95 Correct 133 ms 7760 KB Ok
96 Correct 200 ms 11064 KB Ok
97 Correct 194 ms 10044 KB Ok
98 Correct 152 ms 8924 KB Ok
99 Correct 181 ms 9268 KB Ok
100 Correct 207 ms 9268 KB Ok
101 Correct 196 ms 10044 KB Ok
102 Correct 171 ms 9196 KB Ok
103 Correct 182 ms 9400 KB Ok
104 Correct 221 ms 11228 KB Ok
105 Correct 215 ms 10284 KB Ok
106 Correct 156 ms 9704 KB Ok
107 Correct 182 ms 10060 KB Ok
108 Correct 207 ms 10712 KB Ok
109 Correct 194 ms 10348 KB Ok
110 Correct 342 ms 23236 KB Ok
111 Correct 360 ms 31252 KB Ok
112 Correct 349 ms 25088 KB Ok
113 Correct 367 ms 28240 KB Ok
114 Correct 368 ms 29508 KB Ok
115 Correct 370 ms 28832 KB Ok
116 Correct 365 ms 28736 KB Ok
117 Correct 348 ms 29292 KB Ok
118 Correct 377 ms 25892 KB Ok
119 Correct 364 ms 29908 KB Ok
120 Correct 354 ms 26052 KB Ok
121 Correct 335 ms 24832 KB Ok
122 Correct 348 ms 27436 KB Ok
123 Correct 360 ms 31172 KB Ok
124 Correct 355 ms 22632 KB Ok
125 Correct 312 ms 13516 KB Ok