Submission #40456

#TimeUsernameProblemLanguageResultExecution timeMemory
40456PajarajaNice sequence (IZhO18_sequence)C++14
100 / 100
1612 ms52904 KiB
#include <bits/stdc++.h> using namespace std; vector<int> g[400007]; int pv[400007],deg[400007],parc[400007]; int nzd(int a,int b) { if(a==0) return b; return nzd(b%a,a); } int main() { int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); int x=m+n-1-nzd(m,n); printf("%d\n",x); fill(deg,deg+x+1,0); for(int i=0;i<=x;i++) g[i].clear(); for(int i=n;i<=x;i++) { g[i].push_back(i-n); deg[i-n]++; } for(int i=m;i<=x;i++) { g[i-m].push_back(i); deg[i]++; } queue<int> q; for(int i=0;i<=x;i++) if(deg[i]==0) q.push(i); int cnt=0; while(!q.empty()) { int u=q.front(); pv[u]=cnt++; q.pop(); for(int i=0;i<g[u].size();i++) { deg[g[u][i]]--; if(deg[g[u][i]]==0) q.push(g[u][i]); } } for(int i=1;i<=x;i++) printf("%d ",pv[i]-pv[i-1]); printf("\n"); } }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<g[u].size();i++) 
                 ^
sequence.cpp:13:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&t);
                ^
sequence.cpp:17:22: 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...