Submission #507148

#TimeUsernameProblemLanguageResultExecution timeMemory
507148MazaalaiNice sequence (IZhO18_sequence)C++17
15 / 100
10 ms716 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; int n, m, mul; const int N = 2e5 + 5; int arr[2*N]; bool vis[2*N]; void go() { mul = -1; cin >> n >> m; for (int i = 0; i <= m*2; i++) { vis[i] = 0; arr[i] = 0; } if (m < n) { swap(n, m); mul = 1; } if (m % n == 0) { cout << m-1 << '\n'; for (int i = 1; i < m; i++) cout << 1 * mul << " \n"[i==m-1]; return; } if (n == 2) { cout << m << '\n'; for (int i = 1; i <= m; i++) cout << (i & 1 ? -m : m+1) * mul << " \n"[i==m]; return; } int i = 0, j = (m)%n, smol = (m-1)%n; vector <int> pos; while(1) { if (!vis[i]) { vis[i] = 1; pos.pb(i); } if (!vis[j]) { vis[j] = 1; pos.pb(j); } i = (i + 1) % n; j = (j + 1) % n; if (i == n-1) break; } int lst = 0; for (i = 0; i < n; i++) if (pos[i] <= smol) lst = i; int Y = pos[lst]; // 0->x, 1->y Y = (Y+1)%n; int a, b, c = m / n + 1, d, x, y; a = n-1, b = 1; d = c+1, c = m - d; x = 10 * d; y = 10 * a * d - 1; lst = 1; while(1) { int curNum = (lst%n == Y) ? -y : x; arr[lst] = arr[lst-1] + curNum; if (lst >= n) { int tmp = arr[lst] - (lst-n >= 0 ? arr[lst-n] : 0); if (tmp <= 0) { break; } } if (lst >= m) { int tmp = arr[lst] - (lst-m >= 0 ? arr[lst-m] : 0); if (tmp >= 0) { break; } } if (lst > 2*m) { cout << "GG\n"; cout << n << ' ' << m << '\n'; exit(0); break; } lst++; } cout << lst-1 << '\n'; for (int i = 1; i < lst; i++) cout << arr[i]-arr[i-1] << " \n"[i==lst-1]; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int T; cin >> T; while(T--) go(); }

Compilation message (stderr)

sequence.cpp: In function 'void go()':
sequence.cpp:51:9: warning: variable 'b' set but not used [-Wunused-but-set-variable]
   51 |  int a, b, c = m / n + 1, d, x, y;
      |         ^
#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...