Submission #40508

#TimeUsernameProblemLanguageResultExecution timeMemory
40508AkylbekNice sequence (IZhO18_sequence)C++14
100 / 100
1743 ms73296 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; const int N = 4e5 + 10; const int md = 1e9 + 7; int T; int n, m; vector <int> g[N]; int p[N]; int used[N]; vector <int> ord; void dfs (int v) { used[v] = 1; for (auto to : g[v]) { if (!used[to]) dfs(to); } ord.pb(v); } int main() { scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); int len = n + m - __gcd(n, m) - 1; for (int i = n; i <= len; i++) { g[i - n].pb(i); } for (int i = m; i <= len; i++) { g[i].pb(i - m); } for (int i = 0; i <= len; i++) { if (!used[i]) { dfs(i); } } for (int i = 0; i < len + 1; i++) { if (ord[i] == 0) { p[ord[i]] = 0; continue; } if (i == 0) { p[ord[i]] = -1000000; continue; } p[ord[i]] = p[ord[i - 1]] + 1; } cout << len << '\n'; for (int i = 1; i <= len; i++) { cout << p[i] - p[i - 1] << ' '; } cout << '\n'; for (int i = 0; i <= len; i++) { g[i].clear(); used[i] = 0; } ord.clear(); } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:33:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &T);
                 ^
sequence.cpp:35:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   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...