Submission #40506

#TimeUsernameProblemLanguageResultExecution timeMemory
40506AkylbekNice sequence (IZhO18_sequence)C++14
0 / 100
5 ms5212 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; const int N = 2e5 + 10; const int md = 1e9 + 7; int T; int n, m; vector <int> g[N]; int p[N]; int used[N]; void dfs (int v) { used[v] = 1; for (auto to : g[v]) { if (!used[to]) dfs(to); } if (v == 0) p[v] = 0; else { p[v] = -1000000; for (auto to : g[v]) { p[v] = max(p[v], p[to] + 1); } } } 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; i++) { g[i].clear(); used[i] = 0; } cout << len << '\n'; for (int i = 1; i <= len; i++) { cout << p[i] - p[i - 1] << ' '; } cout << '\n'; } return 0; }

Compilation message (stderr)

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