Submission #909922

#TimeUsernameProblemLanguageResultExecution timeMemory
909922daoquanglinh2007Nice sequence (IZhO18_sequence)C++17
29 / 100
2031 ms4184 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define isz(a) (int)(a).size() const int NM = 4e5, LIM = 1e6; 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; dfs(i); } cout << k << '\n'; for (int i = 1; i <= k; i++){ cout << sum[i]-sum[i-1] << ' '; } cout << '\n'; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...