답안 #388407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388407 2021-04-11T11:28:32 Z lukameladze Binary Subsequences (info1cup17_binary) C++14
100 / 100
675 ms 332 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
int t,raod,rem,cnt,xx,bb,x,y,k,ans,idx,mn,ww,anss1;
void go(int x, int y, int raod) {
     if (x==0 && y==0) {
          anss1=raod;
     }
     if (x==y && x!=0) anss1=-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) return ;
     if (x>y) {
          cout<<0<<" ";
          go1(x-y-1, y);
     }
     else
     if (x<y) {
          cout<<1<<" ";
          go1(x,y-x-1);
     }
}
int main() {
     std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>t;
     while (t--) {
          cin>>k;
          mn=1e9;ans=0;
          for (int x=0; x<=k/2; x++) {
               go(x,k-x,0);
               if (anss1!=-1) {
                    ans+=2;
                    if (mn>anss1) {
                         mn=anss1;
                         idx=x;
                    }
               }
          }
          cout<<ans<<endl;
          go1(idx,k-idx);
          cout<<endl;
     }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 204 KB Output is correct
2 Correct 56 ms 204 KB Output is correct
3 Correct 55 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 660 ms 204 KB Output is correct
2 Correct 675 ms 204 KB Output is correct
3 Correct 653 ms 208 KB Output is correct