# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334804 | juggernaut | Nice sequence (IZhO18_sequence) | C++14 | 2047 ms | 42088 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];
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)
# | 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... |