Submission #789551

# Submission time Handle Problem Language Result Execution time Memory
789551 2023-07-21T13:33:27 Z temporary_juggernaut Nice sequence (IZhO18_sequence) C++14
100 / 100
642 ms 43264 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...) printf(args)
#else
    #define printl(args...) 0
#endif
int n, m;
int timer, len;
bool used[800005];
int pref[400005];
void dfs(int v){
	used[v] = true;
	{
		int to = v - m;
		if(to >= 0 && !used[to])
			dfs(to);
	}
	{
		int to = v + n;
		if(to <= len && !used[to])
			dfs(to);
	}
	pref[v] = timer++;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tests;
  	cin >> tests;
	while(tests--){
		cin >> n >> m;
		priority_queue<int, vector<int>, greater<int> >q;
		int mx = 0;
		timer = 0;
		q.push(0);
		while(!q.empty()){
			int v = q.top();
			q.pop();
			used[v] = 1;
			umax(mx, v);
			{
				int to = v - m;
				if(to >= 0){
					if(used[to])
						break;
					else
						q.push(to);
				}
			}
			{
				int to = v + n;
				if(used[to])
					break;
				else
					q.push(to);
			}
		}
		len = mx - 1;
		fill(used, used + mx + 1, false);
		for(int i = 0; i <= len; i++)
			if(!used[i])
				dfs(i);
		cout << len << '\n';
		fill(used, used + len + 1, false);
		if(len){
			for(int i = 1; i <= len; i++)
				cout << pref[i] - pref[i - 1] << ' ';
			cout << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 1 ms 328 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 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 1 ms 340 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 212 KB Ok
3 Correct 1 ms 324 KB Ok
4 Correct 0 ms 340 KB Ok
5 Correct 1 ms 324 KB Ok
6 Correct 2 ms 328 KB Ok
7 Correct 7 ms 964 KB Ok
8 Correct 3 ms 596 KB Ok
9 Correct 10 ms 980 KB Ok
10 Correct 5 ms 768 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 1 ms 340 KB Ok
4 Correct 0 ms 328 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 0 ms 340 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 1 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 1 ms 340 KB Ok
11 Correct 1 ms 212 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 1 ms 212 KB Ok
3 Correct 1 ms 324 KB Ok
4 Correct 1 ms 320 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 94 ms 6860 KB Ok
7 Correct 101 ms 10272 KB Ok
8 Correct 179 ms 13288 KB Ok
9 Correct 131 ms 11836 KB Ok
10 Correct 71 ms 5284 KB Ok
11 Correct 119 ms 8680 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 1 ms 328 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 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 1 ms 340 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 1 ms 340 KB Ok
15 Correct 1 ms 340 KB Ok
16 Correct 0 ms 328 KB Ok
17 Correct 1 ms 212 KB Ok
18 Correct 0 ms 340 KB Ok
19 Correct 1 ms 212 KB Ok
20 Correct 1 ms 212 KB Ok
21 Correct 0 ms 212 KB Ok
22 Correct 1 ms 340 KB Ok
23 Correct 1 ms 212 KB Ok
24 Correct 2 ms 340 KB Ok
25 Correct 1 ms 340 KB Ok
26 Correct 1 ms 340 KB Ok
27 Correct 1 ms 340 KB Ok
28 Correct 1 ms 340 KB Ok
29 Correct 2 ms 340 KB Ok
30 Correct 1 ms 340 KB Ok
31 Correct 2 ms 340 KB Ok
32 Correct 1 ms 340 KB Ok
33 Correct 1 ms 340 KB Ok
34 Correct 5 ms 452 KB Ok
35 Correct 4 ms 588 KB Ok
36 Correct 4 ms 596 KB Ok
37 Correct 5 ms 596 KB Ok
38 Correct 4 ms 596 KB Ok
39 Correct 3 ms 468 KB Ok
40 Correct 4 ms 596 KB Ok
41 Correct 6 ms 540 KB Ok
42 Correct 4 ms 468 KB Ok
43 Correct 5 ms 596 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 1 ms 328 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 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 1 ms 340 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 1 ms 212 KB Ok
15 Correct 1 ms 324 KB Ok
16 Correct 0 ms 340 KB Ok
17 Correct 1 ms 324 KB Ok
18 Correct 2 ms 328 KB Ok
19 Correct 7 ms 964 KB Ok
20 Correct 3 ms 596 KB Ok
21 Correct 10 ms 980 KB Ok
22 Correct 5 ms 768 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 1 ms 340 KB Ok
25 Correct 1 ms 340 KB Ok
26 Correct 0 ms 328 KB Ok
27 Correct 1 ms 212 KB Ok
28 Correct 0 ms 340 KB Ok
29 Correct 1 ms 212 KB Ok
30 Correct 1 ms 212 KB Ok
31 Correct 0 ms 212 KB Ok
32 Correct 1 ms 340 KB Ok
33 Correct 1 ms 212 KB Ok
34 Correct 2 ms 340 KB Ok
35 Correct 1 ms 340 KB Ok
36 Correct 1 ms 340 KB Ok
37 Correct 1 ms 340 KB Ok
38 Correct 1 ms 340 KB Ok
39 Correct 2 ms 340 KB Ok
40 Correct 1 ms 340 KB Ok
41 Correct 2 ms 340 KB Ok
42 Correct 1 ms 340 KB Ok
43 Correct 1 ms 340 KB Ok
44 Correct 5 ms 452 KB Ok
45 Correct 4 ms 588 KB Ok
46 Correct 4 ms 596 KB Ok
47 Correct 5 ms 596 KB Ok
48 Correct 4 ms 596 KB Ok
49 Correct 3 ms 468 KB Ok
50 Correct 4 ms 596 KB Ok
51 Correct 6 ms 540 KB Ok
52 Correct 4 ms 468 KB Ok
53 Correct 5 ms 596 KB Ok
54 Correct 44 ms 2388 KB Ok
55 Correct 42 ms 2724 KB Ok
56 Correct 50 ms 2684 KB Ok
57 Correct 30 ms 1996 KB Ok
58 Correct 36 ms 2220 KB Ok
59 Correct 34 ms 2056 KB Ok
60 Correct 30 ms 1900 KB Ok
61 Correct 31 ms 2012 KB Ok
62 Correct 42 ms 2508 KB Ok
63 Correct 33 ms 2124 KB Ok
64 Correct 41 ms 2764 KB Ok
65 Correct 38 ms 2380 KB Ok
66 Correct 34 ms 2196 KB Ok
67 Correct 31 ms 2060 KB Ok
68 Correct 35 ms 2164 KB Ok
69 Correct 127 ms 10208 KB Ok
70 Correct 140 ms 10824 KB Ok
71 Correct 105 ms 9904 KB Ok
72 Correct 134 ms 10140 KB Ok
73 Correct 135 ms 9428 KB Ok
74 Correct 100 ms 9296 KB Ok
75 Correct 103 ms 9584 KB Ok
76 Correct 143 ms 10408 KB Ok
77 Correct 92 ms 8856 KB Ok
78 Correct 140 ms 9584 KB Ok
79 Correct 128 ms 10136 KB Ok
80 Correct 124 ms 10032 KB Ok
81 Correct 126 ms 9712 KB Ok
82 Correct 121 ms 9976 KB Ok
83 Correct 103 ms 9248 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 1 ms 328 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 1 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 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 1 ms 340 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 1 ms 212 KB Ok
15 Correct 1 ms 324 KB Ok
16 Correct 0 ms 340 KB Ok
17 Correct 1 ms 324 KB Ok
18 Correct 2 ms 328 KB Ok
19 Correct 7 ms 964 KB Ok
20 Correct 3 ms 596 KB Ok
21 Correct 10 ms 980 KB Ok
22 Correct 5 ms 768 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 1 ms 340 KB Ok
25 Correct 1 ms 340 KB Ok
26 Correct 0 ms 328 KB Ok
27 Correct 1 ms 212 KB Ok
28 Correct 0 ms 340 KB Ok
29 Correct 1 ms 212 KB Ok
30 Correct 1 ms 212 KB Ok
31 Correct 0 ms 212 KB Ok
32 Correct 1 ms 340 KB Ok
33 Correct 1 ms 212 KB Ok
34 Correct 1 ms 212 KB Ok
35 Correct 1 ms 212 KB Ok
36 Correct 1 ms 324 KB Ok
37 Correct 1 ms 320 KB Ok
38 Correct 1 ms 340 KB Ok
39 Correct 94 ms 6860 KB Ok
40 Correct 101 ms 10272 KB Ok
41 Correct 179 ms 13288 KB Ok
42 Correct 131 ms 11836 KB Ok
43 Correct 71 ms 5284 KB Ok
44 Correct 119 ms 8680 KB Ok
45 Correct 2 ms 340 KB Ok
46 Correct 1 ms 340 KB Ok
47 Correct 1 ms 340 KB Ok
48 Correct 1 ms 340 KB Ok
49 Correct 1 ms 340 KB Ok
50 Correct 2 ms 340 KB Ok
51 Correct 1 ms 340 KB Ok
52 Correct 2 ms 340 KB Ok
53 Correct 1 ms 340 KB Ok
54 Correct 1 ms 340 KB Ok
55 Correct 5 ms 452 KB Ok
56 Correct 4 ms 588 KB Ok
57 Correct 4 ms 596 KB Ok
58 Correct 5 ms 596 KB Ok
59 Correct 4 ms 596 KB Ok
60 Correct 3 ms 468 KB Ok
61 Correct 4 ms 596 KB Ok
62 Correct 6 ms 540 KB Ok
63 Correct 4 ms 468 KB Ok
64 Correct 5 ms 596 KB Ok
65 Correct 44 ms 2388 KB Ok
66 Correct 42 ms 2724 KB Ok
67 Correct 50 ms 2684 KB Ok
68 Correct 30 ms 1996 KB Ok
69 Correct 36 ms 2220 KB Ok
70 Correct 34 ms 2056 KB Ok
71 Correct 30 ms 1900 KB Ok
72 Correct 31 ms 2012 KB Ok
73 Correct 42 ms 2508 KB Ok
74 Correct 33 ms 2124 KB Ok
75 Correct 41 ms 2764 KB Ok
76 Correct 38 ms 2380 KB Ok
77 Correct 34 ms 2196 KB Ok
78 Correct 31 ms 2060 KB Ok
79 Correct 35 ms 2164 KB Ok
80 Correct 127 ms 10208 KB Ok
81 Correct 140 ms 10824 KB Ok
82 Correct 105 ms 9904 KB Ok
83 Correct 134 ms 10140 KB Ok
84 Correct 135 ms 9428 KB Ok
85 Correct 100 ms 9296 KB Ok
86 Correct 103 ms 9584 KB Ok
87 Correct 143 ms 10408 KB Ok
88 Correct 92 ms 8856 KB Ok
89 Correct 140 ms 9584 KB Ok
90 Correct 128 ms 10136 KB Ok
91 Correct 124 ms 10032 KB Ok
92 Correct 126 ms 9712 KB Ok
93 Correct 121 ms 9976 KB Ok
94 Correct 103 ms 9248 KB Ok
95 Correct 89 ms 5720 KB Ok
96 Correct 127 ms 7660 KB Ok
97 Correct 119 ms 6892 KB Ok
98 Correct 93 ms 5824 KB Ok
99 Correct 112 ms 6260 KB Ok
100 Correct 113 ms 6476 KB Ok
101 Correct 117 ms 6760 KB Ok
102 Correct 114 ms 6612 KB Ok
103 Correct 136 ms 6664 KB Ok
104 Correct 158 ms 7892 KB Ok
105 Correct 122 ms 7460 KB Ok
106 Correct 109 ms 7272 KB Ok
107 Correct 117 ms 7124 KB Ok
108 Correct 130 ms 7884 KB Ok
109 Correct 125 ms 7756 KB Ok
110 Correct 439 ms 39804 KB Ok
111 Correct 607 ms 43072 KB Ok
112 Correct 467 ms 39440 KB Ok
113 Correct 574 ms 43152 KB Ok
114 Correct 556 ms 42536 KB Ok
115 Correct 589 ms 40948 KB Ok
116 Correct 578 ms 42224 KB Ok
117 Correct 595 ms 42312 KB Ok
118 Correct 481 ms 42684 KB Ok
119 Correct 609 ms 41796 KB Ok
120 Correct 514 ms 41764 KB Ok
121 Correct 475 ms 39724 KB Ok
122 Correct 578 ms 41692 KB Ok
123 Correct 642 ms 43264 KB Ok
124 Correct 450 ms 37408 KB Ok
125 Correct 583 ms 26580 KB Ok