# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97768 | KLPP | Binary Subsequences (info1cup17_binary) | C++14 | 922 ms | 384 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;
typedef long long int lld;
typedef pair<lld,lld> pii;
int main(){
int T;
scanf("%d",&T);
while(T--){
int K;
scanf("%d",&K);
lld ans1=0;
lld ans2=1000000000;
vector<int> v;
//cout<<-1<<endl;
pii best;
for(int t=0;t*2<K;t++){
lld can=0;
vector<int> seq;
pii p=pii(t,K-t);
while(p.first!=0 || p.second!=0){
//cout<<p.first<<" "<<p.second<<endl;
if(p.first>p.second){
can+=p.first/(p.second+1);
p.first%=(p.second+1);
}
else{
if(p.first<p.second){
can+=p.second/(p.first+1);
p.second%=(p.first+1);
}
else{
can=-1;
break;
}
}
}//cout<<t<<" "<<K-t<<" "<<can<<endl;
if(can!=-1)ans1++;
if(can<ans2 && can!=-1){
best=pii(t,K-t);
ans2=can;
}
}
printf("%d\n",ans1*2);
pii p=best;
//cout<<best.first<<" "<<best.second<<endl;
while(p.first!=0 || p.second!=0){
//cout<<p.first<<" "<<p.second<<endl;
if(p.first>p.second){
p.first-=p.second+1;
v.push_back(0);
}
else{
if(p.first<p.second){v.push_back(1);
p.second-=p.first+1;
}
else{
break;
}
}
}
for(int i=0;i<v.size();i++)printf("%d ",v[i]);
printf("\n");
}
return 0;
}
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... |