Submission #760591

# Submission time Handle Problem Language Result Execution time Memory
760591 2023-06-17T23:18:13 Z NK_ Gift (IZhO18_nicegift) C++17
0 / 100
3 ms 592 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())

using ll = long long;
template<class T> using V = vector<T>;

void solve() {
	int N, M; cin >> N >> M;

	// P[i] - P[i - M] > 0 => P[i] > P[i - M];
	// P[i - N] - P[i] > 0 => P[i] > P[i + N];

	int K = N + M - gcd(N, M);

	V<int> deg(K);
	for(int i = 0; i < K; i++) {
		for(auto v : V<int>{i - M, i + N}) {
			if (v < 0 || v >= K) continue;
			deg[v]++;
		}
	}


	queue<int> q; for(int i = 0; i < K; i++) {
		if (deg[i] == 0) q.push(i);
	}

	int cur = K;
	V<int> P(K);

	while(sz(q)) {
		int u = q.front(); q.pop();

		P[u] = cur--;

		for(auto v : V<int>{u - M, u + N}) {
			if (v < 0 || v >= K) continue;
			--deg[v];
			if (deg[v] == 0) q.push(v);
		}
	}

	cout << K - 1 << nl;
	for(int i = 1; i < K; i++) {
		cout << P[i] - P[i - 1] << " ";
	}
	cout << nl;
}	

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int T; cin >> T;
	while(T--) {
		solve();
	}

    return 0;
}


# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Added number should be positive
2 Halted 0 ms 0 KB -