Submission #797341

#TimeUsernameProblemLanguageResultExecution timeMemory
797341kingfran1907Nice sequence (IZhO18_sequence)C++14
100 / 100
361 ms42788 KiB
#include <bits/stdc++.h> using namespace std; typedef long long llint; const int maxn = 1e6+10; int t; int n, m; int dis[maxn]; int out[maxn]; int sol; int cnt; void dfs(int x) { if (x < 0 || x > sol) return; if (dis[x] != -1) return; dis[x] = maxn; dfs(x + n); dfs(x - m); dis[x] = cnt++; } int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); sol = n + m - 1 - __gcd(n, m); printf("%d\n", sol); if (n == m) { for (int i = 0; i < sol; i++) printf("1 "); printf("\n"); continue; } for (int i = 0; i <= sol; i++) dis[i] = -1; cnt = 0; for (int i = 0; i <= sol; i++) { if (dis[i] == -1) dfs(i); } //for (int i = 0; i <= sol; i++) printf("%d ", dis[i]); printf("\n"); for (int i = 0; i < sol; i++) out[i] = dis[i + 1] - dis[i]; for (int i = n; i <= sol; i++) assert(dis[i] - dis[i - n] <= -1); for (int i = m; i <= sol; i++) assert(dis[i] - dis[i - m] >= 1); for (int i = 0; i < sol; i++) printf("%d ", out[i]); printf("\n"); } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
sequence.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
#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...