답안 #389460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389460 2021-04-14T06:21:24 Z i_am_noob Binary Subsequences (info1cup17_binary) C++17
82 / 100
900 ms 356 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
//#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define inf 0x3f3f3f3f

#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif

const int maxn=2005,mod=1000000007;

int t,n,cnt,minn,minid;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> t;
    while(t--){
        cin >> n;
        n+=2;
        cnt=0;
        minn=inf;
        rep2(i,1,n) if(__gcd(i,n)==1){
            cnt++;
            int a=i,b=n-i,x=0;
            while(a>1&&b>1){
                if(a>b){
                    x+=a/b;
                    a%=b;
                }
                else{
                    x+=b/a;
                    b%=a;
                }
                if(x>=minn) break;
            }
            if(a>b) x+=a-1;
            if(b>a) x+=b-1;
            if(x<minn) minn=x,minid=i;
        }
        cout << cnt << "\n";
        vector<int> vec;
        int a=minid,b=n-minid;
        while(a>1&&b>1){
            if(a>b){
                rep(a/b) vec.pb(1);
                a%=b;
            }
            else{
                rep(b/a) vec.pb(0);
                b%=a;
            }
        }
        if(a>b) rep(a-1) vec.pb(1);
        if(b>a) rep(b-1) vec.pb(0);
        for(auto i: vec) cout << i << ' ';
        cout << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 324 KB Output is correct
2 Correct 103 ms 292 KB Output is correct
3 Correct 95 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 998 ms 296 KB Time limit exceeded
2 Halted 0 ms 0 KB -