Submission #90509

# Submission time Handle Problem Language Result Execution time Memory
90509 2018-12-22T04:00:40 Z Just_Solve_The_Problem Nice sequence (IZhO18_sequence) C++11
100 / 100
609 ms 43728 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)4e5 + 7;

int used[N];
int tiktak, n, m, len;
int tout[N];

void dfs(int v) {
	used[v] = 1;
	if (v > m && !used[v - m]) {
		dfs(v - m);
	}
	if (v + n <= len && !used[v + n]) {
		dfs(v + n);
	}
	tiktak++;
	tout[v] = tiktak;
}

void solve() {
	int tiktak = 0;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n + m; i++) {
		used[i] = 0;
	}
	if (n == m) {
		printf("%d\n", n - 1);
		for (int i = 1; i < n; i++) {
			printf("1 ");
		}
		puts("");
		return ;
	}
	len = n + m - __gcd(n, m);
	for (int i = 1; i <= len; i++) {
		if (!used[i]) {
			dfs(i);
		}
	}
	printf("%d\n", len - 1);
	for (int i = 1; i < len; i++) {
		printf("%d ", tout[i + 1] - tout[i]);
	}
	puts("");
}

main() {
	int test;
	scanf("%d", &test);
	while (test--) {
		solve();
	}
}

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:24:6: warning: unused variable 'tiktak' [-Wunused-variable]
  int tiktak = 0;
      ^~~~~~
sequence.cpp: At global scope:
sequence.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sequence.cpp: In function 'void solve()':
sequence.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &test);
  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Ok
2 Correct 2 ms 512 KB Ok
3 Correct 2 ms 624 KB Ok
4 Correct 2 ms 672 KB Ok
5 Correct 2 ms 676 KB Ok
6 Correct 2 ms 804 KB Ok
7 Correct 2 ms 804 KB Ok
8 Correct 2 ms 804 KB Ok
9 Correct 2 ms 804 KB Ok
10 Correct 2 ms 804 KB Ok
11 Correct 2 ms 804 KB Ok
12 Correct 2 ms 844 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Ok
2 Correct 2 ms 852 KB Ok
3 Correct 2 ms 856 KB Ok
4 Correct 2 ms 860 KB Ok
5 Correct 1 ms 864 KB Ok
6 Correct 3 ms 868 KB Ok
7 Correct 9 ms 1384 KB Ok
8 Correct 5 ms 1384 KB Ok
9 Correct 10 ms 1580 KB Ok
10 Correct 6 ms 1580 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1580 KB Ok
2 Correct 2 ms 1580 KB Ok
3 Correct 2 ms 1580 KB Ok
4 Correct 2 ms 1580 KB Ok
5 Correct 2 ms 1580 KB Ok
6 Correct 2 ms 1580 KB Ok
7 Correct 2 ms 1580 KB Ok
8 Correct 2 ms 1580 KB Ok
9 Correct 2 ms 1580 KB Ok
10 Correct 2 ms 1580 KB Ok
11 Correct 2 ms 1580 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1580 KB Ok
2 Correct 2 ms 1580 KB Ok
3 Correct 2 ms 1580 KB Ok
4 Correct 2 ms 1580 KB Ok
5 Correct 2 ms 1580 KB Ok
6 Correct 68 ms 7500 KB Ok
7 Correct 61 ms 10928 KB Ok
8 Correct 115 ms 13632 KB Ok
9 Correct 87 ms 13632 KB Ok
10 Correct 47 ms 13632 KB Ok
11 Correct 75 ms 13632 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Ok
2 Correct 2 ms 512 KB Ok
3 Correct 2 ms 624 KB Ok
4 Correct 2 ms 672 KB Ok
5 Correct 2 ms 676 KB Ok
6 Correct 2 ms 804 KB Ok
7 Correct 2 ms 804 KB Ok
8 Correct 2 ms 804 KB Ok
9 Correct 2 ms 804 KB Ok
10 Correct 2 ms 804 KB Ok
11 Correct 2 ms 804 KB Ok
12 Correct 2 ms 844 KB Ok
13 Correct 2 ms 1580 KB Ok
14 Correct 2 ms 1580 KB Ok
15 Correct 2 ms 1580 KB Ok
16 Correct 2 ms 1580 KB Ok
17 Correct 2 ms 1580 KB Ok
18 Correct 2 ms 1580 KB Ok
19 Correct 2 ms 1580 KB Ok
20 Correct 2 ms 1580 KB Ok
21 Correct 2 ms 1580 KB Ok
22 Correct 2 ms 1580 KB Ok
23 Correct 2 ms 1580 KB Ok
24 Correct 4 ms 13632 KB Ok
25 Correct 3 ms 13632 KB Ok
26 Correct 3 ms 13632 KB Ok
27 Correct 3 ms 13632 KB Ok
28 Correct 3 ms 13632 KB Ok
29 Correct 3 ms 13632 KB Ok
30 Correct 3 ms 13632 KB Ok
31 Correct 3 ms 13632 KB Ok
32 Correct 3 ms 13632 KB Ok
33 Correct 3 ms 13632 KB Ok
34 Correct 4 ms 13632 KB Ok
35 Correct 4 ms 13632 KB Ok
36 Correct 4 ms 13632 KB Ok
37 Correct 4 ms 13632 KB Ok
38 Correct 4 ms 13632 KB Ok
39 Correct 4 ms 13632 KB Ok
40 Correct 4 ms 13632 KB Ok
41 Correct 5 ms 13632 KB Ok
42 Correct 5 ms 13632 KB Ok
43 Correct 5 ms 13632 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Ok
2 Correct 2 ms 512 KB Ok
3 Correct 2 ms 624 KB Ok
4 Correct 2 ms 672 KB Ok
5 Correct 2 ms 676 KB Ok
6 Correct 2 ms 804 KB Ok
7 Correct 2 ms 804 KB Ok
8 Correct 2 ms 804 KB Ok
9 Correct 2 ms 804 KB Ok
10 Correct 2 ms 804 KB Ok
11 Correct 2 ms 804 KB Ok
12 Correct 2 ms 844 KB Ok
13 Correct 2 ms 844 KB Ok
14 Correct 2 ms 852 KB Ok
15 Correct 2 ms 856 KB Ok
16 Correct 2 ms 860 KB Ok
17 Correct 1 ms 864 KB Ok
18 Correct 3 ms 868 KB Ok
19 Correct 9 ms 1384 KB Ok
20 Correct 5 ms 1384 KB Ok
21 Correct 10 ms 1580 KB Ok
22 Correct 6 ms 1580 KB Ok
23 Correct 2 ms 1580 KB Ok
24 Correct 2 ms 1580 KB Ok
25 Correct 2 ms 1580 KB Ok
26 Correct 2 ms 1580 KB Ok
27 Correct 2 ms 1580 KB Ok
28 Correct 2 ms 1580 KB Ok
29 Correct 2 ms 1580 KB Ok
30 Correct 2 ms 1580 KB Ok
31 Correct 2 ms 1580 KB Ok
32 Correct 2 ms 1580 KB Ok
33 Correct 2 ms 1580 KB Ok
34 Correct 4 ms 13632 KB Ok
35 Correct 3 ms 13632 KB Ok
36 Correct 3 ms 13632 KB Ok
37 Correct 3 ms 13632 KB Ok
38 Correct 3 ms 13632 KB Ok
39 Correct 3 ms 13632 KB Ok
40 Correct 3 ms 13632 KB Ok
41 Correct 3 ms 13632 KB Ok
42 Correct 3 ms 13632 KB Ok
43 Correct 3 ms 13632 KB Ok
44 Correct 4 ms 13632 KB Ok
45 Correct 4 ms 13632 KB Ok
46 Correct 4 ms 13632 KB Ok
47 Correct 4 ms 13632 KB Ok
48 Correct 4 ms 13632 KB Ok
49 Correct 4 ms 13632 KB Ok
50 Correct 4 ms 13632 KB Ok
51 Correct 5 ms 13632 KB Ok
52 Correct 5 ms 13632 KB Ok
53 Correct 5 ms 13632 KB Ok
54 Correct 45 ms 13632 KB Ok
55 Correct 57 ms 13632 KB Ok
56 Correct 56 ms 13632 KB Ok
57 Correct 39 ms 13632 KB Ok
58 Correct 48 ms 13632 KB Ok
59 Correct 45 ms 13632 KB Ok
60 Correct 38 ms 13632 KB Ok
61 Correct 39 ms 13632 KB Ok
62 Correct 59 ms 13632 KB Ok
63 Correct 41 ms 13632 KB Ok
64 Correct 56 ms 13632 KB Ok
65 Correct 50 ms 13632 KB Ok
66 Correct 44 ms 13632 KB Ok
67 Correct 36 ms 13632 KB Ok
68 Correct 48 ms 13632 KB Ok
69 Correct 112 ms 13632 KB Ok
70 Correct 128 ms 13632 KB Ok
71 Correct 118 ms 13632 KB Ok
72 Correct 108 ms 13632 KB Ok
73 Correct 114 ms 13632 KB Ok
74 Correct 117 ms 13632 KB Ok
75 Correct 107 ms 13632 KB Ok
76 Correct 115 ms 13632 KB Ok
77 Correct 103 ms 13632 KB Ok
78 Correct 112 ms 13632 KB Ok
79 Correct 115 ms 13632 KB Ok
80 Correct 116 ms 13632 KB Ok
81 Correct 105 ms 13632 KB Ok
82 Correct 107 ms 13632 KB Ok
83 Correct 116 ms 13632 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Ok
2 Correct 2 ms 512 KB Ok
3 Correct 2 ms 624 KB Ok
4 Correct 2 ms 672 KB Ok
5 Correct 2 ms 676 KB Ok
6 Correct 2 ms 804 KB Ok
7 Correct 2 ms 804 KB Ok
8 Correct 2 ms 804 KB Ok
9 Correct 2 ms 804 KB Ok
10 Correct 2 ms 804 KB Ok
11 Correct 2 ms 804 KB Ok
12 Correct 2 ms 844 KB Ok
13 Correct 2 ms 844 KB Ok
14 Correct 2 ms 852 KB Ok
15 Correct 2 ms 856 KB Ok
16 Correct 2 ms 860 KB Ok
17 Correct 1 ms 864 KB Ok
18 Correct 3 ms 868 KB Ok
19 Correct 9 ms 1384 KB Ok
20 Correct 5 ms 1384 KB Ok
21 Correct 10 ms 1580 KB Ok
22 Correct 6 ms 1580 KB Ok
23 Correct 2 ms 1580 KB Ok
24 Correct 2 ms 1580 KB Ok
25 Correct 2 ms 1580 KB Ok
26 Correct 2 ms 1580 KB Ok
27 Correct 2 ms 1580 KB Ok
28 Correct 2 ms 1580 KB Ok
29 Correct 2 ms 1580 KB Ok
30 Correct 2 ms 1580 KB Ok
31 Correct 2 ms 1580 KB Ok
32 Correct 2 ms 1580 KB Ok
33 Correct 2 ms 1580 KB Ok
34 Correct 2 ms 1580 KB Ok
35 Correct 2 ms 1580 KB Ok
36 Correct 2 ms 1580 KB Ok
37 Correct 2 ms 1580 KB Ok
38 Correct 2 ms 1580 KB Ok
39 Correct 68 ms 7500 KB Ok
40 Correct 61 ms 10928 KB Ok
41 Correct 115 ms 13632 KB Ok
42 Correct 87 ms 13632 KB Ok
43 Correct 47 ms 13632 KB Ok
44 Correct 75 ms 13632 KB Ok
45 Correct 4 ms 13632 KB Ok
46 Correct 3 ms 13632 KB Ok
47 Correct 3 ms 13632 KB Ok
48 Correct 3 ms 13632 KB Ok
49 Correct 3 ms 13632 KB Ok
50 Correct 3 ms 13632 KB Ok
51 Correct 3 ms 13632 KB Ok
52 Correct 3 ms 13632 KB Ok
53 Correct 3 ms 13632 KB Ok
54 Correct 3 ms 13632 KB Ok
55 Correct 4 ms 13632 KB Ok
56 Correct 4 ms 13632 KB Ok
57 Correct 4 ms 13632 KB Ok
58 Correct 4 ms 13632 KB Ok
59 Correct 4 ms 13632 KB Ok
60 Correct 4 ms 13632 KB Ok
61 Correct 4 ms 13632 KB Ok
62 Correct 5 ms 13632 KB Ok
63 Correct 5 ms 13632 KB Ok
64 Correct 5 ms 13632 KB Ok
65 Correct 45 ms 13632 KB Ok
66 Correct 57 ms 13632 KB Ok
67 Correct 56 ms 13632 KB Ok
68 Correct 39 ms 13632 KB Ok
69 Correct 48 ms 13632 KB Ok
70 Correct 45 ms 13632 KB Ok
71 Correct 38 ms 13632 KB Ok
72 Correct 39 ms 13632 KB Ok
73 Correct 59 ms 13632 KB Ok
74 Correct 41 ms 13632 KB Ok
75 Correct 56 ms 13632 KB Ok
76 Correct 50 ms 13632 KB Ok
77 Correct 44 ms 13632 KB Ok
78 Correct 36 ms 13632 KB Ok
79 Correct 48 ms 13632 KB Ok
80 Correct 112 ms 13632 KB Ok
81 Correct 128 ms 13632 KB Ok
82 Correct 118 ms 13632 KB Ok
83 Correct 108 ms 13632 KB Ok
84 Correct 114 ms 13632 KB Ok
85 Correct 117 ms 13632 KB Ok
86 Correct 107 ms 13632 KB Ok
87 Correct 115 ms 13632 KB Ok
88 Correct 103 ms 13632 KB Ok
89 Correct 112 ms 13632 KB Ok
90 Correct 115 ms 13632 KB Ok
91 Correct 116 ms 13632 KB Ok
92 Correct 105 ms 13632 KB Ok
93 Correct 107 ms 13632 KB Ok
94 Correct 116 ms 13632 KB Ok
95 Correct 117 ms 13632 KB Ok
96 Correct 180 ms 13632 KB Ok
97 Correct 177 ms 13632 KB Ok
98 Correct 118 ms 13632 KB Ok
99 Correct 167 ms 13632 KB Ok
100 Correct 158 ms 13632 KB Ok
101 Correct 159 ms 13632 KB Ok
102 Correct 142 ms 13632 KB Ok
103 Correct 136 ms 13632 KB Ok
104 Correct 172 ms 13632 KB Ok
105 Correct 163 ms 13632 KB Ok
106 Correct 129 ms 13632 KB Ok
107 Correct 154 ms 13632 KB Ok
108 Correct 185 ms 13632 KB Ok
109 Correct 161 ms 13632 KB Ok
110 Correct 529 ms 40972 KB Ok
111 Correct 563 ms 43292 KB Ok
112 Correct 569 ms 43292 KB Ok
113 Correct 516 ms 43544 KB Ok
114 Correct 498 ms 43728 KB Ok
115 Correct 578 ms 43728 KB Ok
116 Correct 504 ms 43728 KB Ok
117 Correct 601 ms 43728 KB Ok
118 Correct 505 ms 43728 KB Ok
119 Correct 529 ms 43728 KB Ok
120 Correct 567 ms 43728 KB Ok
121 Correct 529 ms 43728 KB Ok
122 Correct 567 ms 43728 KB Ok
123 Correct 609 ms 43728 KB Ok
124 Correct 488 ms 43728 KB Ok
125 Correct 308 ms 43728 KB Ok