Submission #909923

# Submission time Handle Problem Language Result Execution time Memory
909923 2024-01-17T15:34:17 Z daoquanglinh2007 Nice sequence (IZhO18_sequence) C++17
43 / 100
2000 ms 10628 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define isz(a) (int)(a).size()
 
const int NM = 4e5, LIM = 1e3;
 
int T, N, M, k;
int sum[NM+5];
bool vis[NM+5];

void dfs(int u){
	vis[u] = 1;
	if (u-N >= 0){
		sum[u-N] = sum[u]+1;
		dfs(u-N);
	}
	if (u+M <= k){
		sum[u+M] = sum[u]+1;
		dfs(u+M);
	}
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> T;
	while (T--){
		cin >> N >> M;
		if (N%M == 0){
			cout << N-1 << '\n';
			for (int i = 1; i < N; i++) cout << 1 << ' ';
			cout << '\n';
			continue;
		}
		if (M%N == 0){
			cout << M-1 << '\n';
			for (int i = 1; i < M; i++) cout << -1 << ' ';
			cout << '\n';
			continue;
		}
		k = N+M-__gcd(N, M)-1;
		memset(vis, 0, sizeof(vis));
		int tmp = 0;
		for (int i = 0; i <= k; i++)
			if (!vis[i]){
				sum[i] = --tmp*LIM;
				dfs(i);
			}
		cout << k << '\n';
		for (int i = 1; i <= k; i++){
			cout << sum[i]-sum[i-1] << ' ';
		}
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 420 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 1 ms 348 KB Ok
8 Correct 0 ms 344 KB Ok
9 Correct 1 ms 348 KB Ok
10 Correct 1 ms 344 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Ok
2 Correct 1 ms 2648 KB Ok
3 Correct 1 ms 2652 KB Ok
4 Correct 1 ms 2652 KB Ok
5 Correct 1 ms 2648 KB Ok
6 Correct 16 ms 2652 KB Ok
7 Correct 331 ms 3144 KB Ok
8 Correct 98 ms 2788 KB Ok
9 Correct 311 ms 3224 KB Ok
10 Correct 148 ms 2900 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Ok
2 Correct 1 ms 348 KB Ok
3 Correct 1 ms 2652 KB Ok
4 Correct 1 ms 2652 KB Ok
5 Correct 1 ms 2652 KB Ok
6 Correct 1 ms 2648 KB Ok
7 Correct 1 ms 2652 KB Ok
8 Correct 1 ms 2648 KB Ok
9 Correct 1 ms 2648 KB Ok
10 Correct 1 ms 2652 KB Ok
11 Correct 1 ms 2652 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Ok
2 Correct 1 ms 2652 KB Ok
3 Correct 1 ms 2652 KB Ok
4 Correct 1 ms 2648 KB Ok
5 Correct 1 ms 2652 KB Ok
6 Execution timed out 2095 ms 4800 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 420 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 1 ms 348 KB Ok
8 Correct 0 ms 344 KB Ok
9 Correct 1 ms 348 KB Ok
10 Correct 1 ms 344 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Correct 1 ms 2652 KB Ok
14 Correct 1 ms 348 KB Ok
15 Correct 1 ms 2652 KB Ok
16 Correct 1 ms 2652 KB Ok
17 Correct 1 ms 2652 KB Ok
18 Correct 1 ms 2648 KB Ok
19 Correct 1 ms 2652 KB Ok
20 Correct 1 ms 2648 KB Ok
21 Correct 1 ms 2648 KB Ok
22 Correct 1 ms 2652 KB Ok
23 Correct 1 ms 2652 KB Ok
24 Correct 2 ms 2648 KB Ok
25 Correct 2 ms 2652 KB Ok
26 Correct 2 ms 2652 KB Ok
27 Correct 2 ms 2652 KB Ok
28 Correct 2 ms 2652 KB Ok
29 Correct 2 ms 2652 KB Ok
30 Correct 2 ms 2652 KB Ok
31 Correct 2 ms 2652 KB Ok
32 Correct 2 ms 2652 KB Ok
33 Correct 2 ms 2648 KB Ok
34 Correct 4 ms 2912 KB Ok
35 Correct 4 ms 2908 KB Ok
36 Correct 9 ms 2908 KB Ok
37 Correct 4 ms 2908 KB Ok
38 Correct 4 ms 2908 KB Ok
39 Correct 4 ms 2908 KB Ok
40 Correct 5 ms 2908 KB Ok
41 Correct 4 ms 2908 KB Ok
42 Correct 4 ms 2908 KB Ok
43 Correct 4 ms 2908 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 420 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 1 ms 348 KB Ok
8 Correct 0 ms 344 KB Ok
9 Correct 1 ms 348 KB Ok
10 Correct 1 ms 344 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Correct 1 ms 2652 KB Ok
14 Correct 1 ms 2648 KB Ok
15 Correct 1 ms 2652 KB Ok
16 Correct 1 ms 2652 KB Ok
17 Correct 1 ms 2648 KB Ok
18 Correct 16 ms 2652 KB Ok
19 Correct 331 ms 3144 KB Ok
20 Correct 98 ms 2788 KB Ok
21 Correct 311 ms 3224 KB Ok
22 Correct 148 ms 2900 KB Ok
23 Correct 1 ms 2652 KB Ok
24 Correct 1 ms 348 KB Ok
25 Correct 1 ms 2652 KB Ok
26 Correct 1 ms 2652 KB Ok
27 Correct 1 ms 2652 KB Ok
28 Correct 1 ms 2648 KB Ok
29 Correct 1 ms 2652 KB Ok
30 Correct 1 ms 2648 KB Ok
31 Correct 1 ms 2648 KB Ok
32 Correct 1 ms 2652 KB Ok
33 Correct 1 ms 2652 KB Ok
34 Correct 2 ms 2648 KB Ok
35 Correct 2 ms 2652 KB Ok
36 Correct 2 ms 2652 KB Ok
37 Correct 2 ms 2652 KB Ok
38 Correct 2 ms 2652 KB Ok
39 Correct 2 ms 2652 KB Ok
40 Correct 2 ms 2652 KB Ok
41 Correct 2 ms 2652 KB Ok
42 Correct 2 ms 2652 KB Ok
43 Correct 2 ms 2648 KB Ok
44 Correct 4 ms 2912 KB Ok
45 Correct 4 ms 2908 KB Ok
46 Correct 9 ms 2908 KB Ok
47 Correct 4 ms 2908 KB Ok
48 Correct 4 ms 2908 KB Ok
49 Correct 4 ms 2908 KB Ok
50 Correct 5 ms 2908 KB Ok
51 Correct 4 ms 2908 KB Ok
52 Correct 4 ms 2908 KB Ok
53 Correct 4 ms 2908 KB Ok
54 Correct 48 ms 6200 KB Ok
55 Correct 56 ms 6988 KB Ok
56 Correct 52 ms 6784 KB Ok
57 Correct 35 ms 5460 KB Ok
58 Correct 51 ms 6484 KB Ok
59 Correct 41 ms 6264 KB Ok
60 Correct 35 ms 5460 KB Ok
61 Correct 37 ms 5716 KB Ok
62 Correct 50 ms 7252 KB Ok
63 Correct 42 ms 5768 KB Ok
64 Correct 59 ms 6896 KB Ok
65 Correct 52 ms 6572 KB Ok
66 Correct 48 ms 6036 KB Ok
67 Correct 43 ms 5204 KB Ok
68 Correct 49 ms 6228 KB Ok
69 Correct 677 ms 10212 KB Ok
70 Correct 252 ms 10628 KB Ok
71 Correct 502 ms 10360 KB Ok
72 Execution timed out 2053 ms 7252 KB Time limit exceeded
73 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 420 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 1 ms 348 KB Ok
8 Correct 0 ms 344 KB Ok
9 Correct 1 ms 348 KB Ok
10 Correct 1 ms 344 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Correct 1 ms 2652 KB Ok
14 Correct 1 ms 2648 KB Ok
15 Correct 1 ms 2652 KB Ok
16 Correct 1 ms 2652 KB Ok
17 Correct 1 ms 2648 KB Ok
18 Correct 16 ms 2652 KB Ok
19 Correct 331 ms 3144 KB Ok
20 Correct 98 ms 2788 KB Ok
21 Correct 311 ms 3224 KB Ok
22 Correct 148 ms 2900 KB Ok
23 Correct 1 ms 2652 KB Ok
24 Correct 1 ms 348 KB Ok
25 Correct 1 ms 2652 KB Ok
26 Correct 1 ms 2652 KB Ok
27 Correct 1 ms 2652 KB Ok
28 Correct 1 ms 2648 KB Ok
29 Correct 1 ms 2652 KB Ok
30 Correct 1 ms 2648 KB Ok
31 Correct 1 ms 2648 KB Ok
32 Correct 1 ms 2652 KB Ok
33 Correct 1 ms 2652 KB Ok
34 Correct 1 ms 2652 KB Ok
35 Correct 1 ms 2652 KB Ok
36 Correct 1 ms 2652 KB Ok
37 Correct 1 ms 2648 KB Ok
38 Correct 1 ms 2652 KB Ok
39 Execution timed out 2095 ms 4800 KB Time limit exceeded
40 Halted 0 ms 0 KB -