Submission #90509

#TimeUsernameProblemLanguageResultExecution timeMemory
90509Just_Solve_The_ProblemNice sequence (IZhO18_sequence)C++11
100 / 100
609 ms43728 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int)4e5 + 7; int used[N]; int tiktak, n, m, len; int tout[N]; void dfs(int v) { used[v] = 1; if (v > m && !used[v - m]) { dfs(v - m); } if (v + n <= len && !used[v + n]) { dfs(v + n); } tiktak++; tout[v] = tiktak; } void solve() { int tiktak = 0; scanf("%d %d", &n, &m); for (int i = 1; i <= n + m; i++) { used[i] = 0; } if (n == m) { printf("%d\n", n - 1); for (int i = 1; i < n; i++) { printf("1 "); } puts(""); return ; } len = n + m - __gcd(n, m); for (int i = 1; i <= len; i++) { if (!used[i]) { dfs(i); } } printf("%d\n", len - 1); for (int i = 1; i < len; i++) { printf("%d ", tout[i + 1] - tout[i]); } puts(""); } main() { int test; scanf("%d", &test); while (test--) { solve(); } }

Compilation message (stderr)

sequence.cpp: In function 'void solve()':
sequence.cpp:24:6: warning: unused variable 'tiktak' [-Wunused-variable]
  int tiktak = 0;
      ^~~~~~
sequence.cpp: At global scope:
sequence.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sequence.cpp: In function 'void solve()':
sequence.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &test);
  ~~~~~^~~~~~~~~~~~~
#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...