Submission #334935

#TimeUsernameProblemLanguageResultExecution timeMemory
334935juggernautNice sequence (IZhO18_sequence)C++14
100 / 100
1908 ms44880 KiB
#include<bits/stdc++.h> using namespace std; int n,m,len,pref[1000005],timer,vis[1000005]; bool flag; void dfs(int v){ vis[v]=1; if(v-m>=0){ if(vis[v-m]==0)dfs(v-m); else if(vis[v-m]==1)flag=false; } if(v+n<=len){ if(vis[v+n]==0)dfs(v+n); else if(vis[v+n]==1)flag=false; } vis[v]=2; pref[v]=timer++; } bool check(int x){ len=x; flag=true; timer=0; for(int i=0;i<=len;i++)vis[i]=0; for(int i=0;i<=len;i++)if(!vis[i])dfs(i); return flag; } int main(){ int test; scanf("%d",&test); while(test--){ scanf("%d%d",&n,&m); int l=0,r=400000; while(l<r){ int mid=(l+r+1)>>1; if(check(mid))l=mid; else r=mid-1; } check(l); printf("%d\n",l); if(l){ for(int i=1;i<=l;i++)printf("%d ",pref[i]-pref[i-1]); puts(""); } } }

Compilation message (stderr)

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