답안 #909929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909929 2024-01-17T15:44:08 Z daoquanglinh2007 Nice sequence (IZhO18_sequence) C++17
6 / 100
1 ms 2420 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int NM = 4e5, LIM = 1e6;
 
int T, N, M, k;
int sum[NM+5];
int cnt[NM+5];

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int get_rand(int l, int r){
	int tmp = rng()%(r-l+1);
	if (tmp < 0) tmp += r-l+1;
	return l + tmp;
}

void dfs(int u){
	cnt[u]++;
	if (u-N >= 0 && cnt[u-N] < 5){
		sum[u-N] = sum[u]+1;
		dfs(u-N);
	}
	if (u+M <= k && cnt[u+M] < 5){
		sum[u+M] = sum[u]+1;
		dfs(u+M);
	}
}

signed main(){
//	freopen("TEST.inp", "r", stdin);
//	freopen("TEST.out", "w", stdout);
	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;
		while (true){
			for (int i = 0; i <= k; i++) cnt[i] = 0;
			for (int i = 0; i <= k; i++)
				if (cnt[i] < 5){
					sum[i] = get_rand(-LIM, LIM);
					dfs(i);
				}
			bool ok = 1;
			for (int i = 1; i <= k; i++)
				if (sum[i] == sum[i-1]) ok = 0;
			if (ok) break;
		}
		cout << k << '\n';
		for (int i = 1; i <= k; i++){
			cout << sum[i]-sum[i-1] << ' ';
		}
		cout << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 348 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 600 KB Ok
6 Correct 1 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2420 KB Ok
2 Correct 1 ms 348 KB Ok
3 Incorrect 1 ms 2396 KB there is incorrect sequence
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 348 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 600 KB Ok
6 Correct 1 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Correct 1 ms 2420 KB Ok
14 Correct 1 ms 348 KB Ok
15 Incorrect 1 ms 2396 KB there is incorrect sequence
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 348 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 600 KB Ok
6 Correct 1 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Incorrect 1 ms 2396 KB there is incorrect sequence
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 348 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 1 ms 600 KB Ok
6 Correct 1 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Incorrect 1 ms 2396 KB there is incorrect sequence
14 Halted 0 ms 0 KB -