Submission #334804

#TimeUsernameProblemLanguageResultExecution timeMemory
334804juggernautNice sequence (IZhO18_sequence)C++14
76 / 100
2047 ms42088 KiB
#include<bits/stdc++.h> using namespace std; int n,m,len,pref[1000005]; bool vis[1000005]; vector<int>top; void dfs(int v){ vis[v]=1; if(v-m>=0&&!vis[v-m])dfs(v-m); if(v+n<=len&&!vis[v+n])dfs(v+n); top.push_back(v); } bool check(int x){ len=x; top.clear(); for(int i=0;i<=len;i++)vis[i]=0; for(int i=0;i<=len;i++)if(!vis[i])dfs(i); for(int i=0;i<=len;i++)pref[top[i]]=i; for(int i=0;i<=len;i++){ if(i-m>=0&&pref[i]<=pref[i-m])return false; if(i+n<=len&&pref[i]<=pref[i+n])return false; } return true; } int main(){ int test; scanf("%d",&test); while(test--){ scanf("%d%d",&n,&m); int l=0,r=500000; 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:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d",&test);
      |     ~~~~~^~~~~~~~~~~~
sequence.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         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...