Submission #760591

#TimeUsernameProblemLanguageResultExecution timeMemory
760591NK_Gift (IZhO18_nicegift)C++17
0 / 100
3 ms592 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...