# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334935 | juggernaut | Nice sequence (IZhO18_sequence) | C++14 | 1908 ms | 44880 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |