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>
#define f first
#define s second
#define pb push_back
using namespace std;
long long t,raod,rem,cnt,xx,bb,x,y,k,ans,idx,mn,ww;
int go(int x, int y, int raod) {
if (x==0 && y==0) {
return raod;
}
if (x==y && x!=0) return -1;
if (x>y) {
bb=y+1;
rem=x%bb;
cnt=(x-rem)/bb;
go(rem,y,raod+cnt);
}
if (x<y) {
bb=x+1;
rem=y%bb;
cnt=(y-rem)/bb;
go(x,rem,raod+cnt);
}
}
void go1(int x, int y) {
if (x==0 && y==0) return;
if (x>y) {
cout<<0<<" ";
go1(x-y-1, y);
}
else
if (x<y) {
cout<<1<<" ";
go1(x,y-x-1);
}
}
int main() {
cin>>t;
while (t--) {
cin>>k;
mn=1e9;ans=0;
for (int x=0; x<=k; x++) {
ww=go(x,k-x,0);
if (ww!=-1) {
ans++;
if (mn>ww) {
mn=ww;
idx=x;
}
}
}
cout<<ans<<endl;
//cout<<idx<<endl;
go1(idx,k-idx);
cout<<endl;
}
}
Compilation message (stderr)
binary.cpp: In function 'int go(int, int, int)':
binary.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
24 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |