Submission #67928

# Submission time Handle Problem Language Result Execution time Memory
67928 2018-08-15T14:30:16 Z tempytemptemp Binary Subsequences (info1cup17_binary) C++14
100 / 100
734 ms 456 KB
/*
  We found Despacito 5 during contest (not clickbait)
*/
#include	<iostream>
#include	<cstdio>
#include	<vector>
#include 	<set>
#include	<map>
#include	<queue>
#include	<stack>
#include	<algorithm>
#include	<cstring>
#include	<cfloat>
#include	<cmath>
#include	<cassert>
#include	<locale>
#include	<string>
#include	<bitset>
#include	<functional>
#include	<climits>
#include	<iomanip>
using namespace std;

#define read(x)     freopen(x,"r",stdin)
#define write(x)    freopen(x,"w",stdout)
#define cl(a,b)	    memset(a,b,sizeof(a))
#define all(x)      x.begin(),x.end()
#define rall(x)     x.rbegin(),x.rend()
#define ll          long long
#define ld          long double
#define vec         vector
#define vi          vec<int>
#define heap        priority_queue
#define res         reserve
#define pb          push_back
#define f(x,y,z)    for(int x=(y); x<(z); x++)
#define fd(x,y,z)   for(int x=(y); x>=(z); x--)
#define fit(x,y)    for(auto x: y)
#define srt(x)      sort(all(x))
#define rsrt(x)     sort(rall(x))
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define pii         pair<int,int>
#define ppi         pair<pii,int>
#define pip         pair<int,pii>
#define mp          make_pair
#define f1          first
#define s2          second
#define cdbg(x)     cerr<<#x<<" = "<<x<<",\t";
#define cdbl        cerr<<"\n----------\n";
#define pow2(x)     ((x)*(x))
#define edist(x1, y1, x2, y2) (sqrt((pow2(x1-x2)+pow2(y1-y2))))
#define mdist(x1, y1, x2, y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define y1          FullSensei
#define mid         ((ss+se)>>1)
#define left        (si<<1)
#define right       ((si<<1)+1)
#define pi          3.141592653589793
#define popcount    __builtin_popcount
#define spc			' '
#define endl		'\n'
#define lb          lower_bound
bool checkbit(int x,int y){return (x&(1<<y));}
int setbit(int x,int y){return (x^(1<<y));}
const int dirs[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int mod=1e9+7;
const int p1=805306457;
const int p2=1610612741;
const int INF=1e9;
const int N=1e5+7;
int a[N];
int tc, k;

void ans(pii best){
	int x=best.f1, y=best.s2;
	while(x>1 || y>1){
		if(x>y){
			x-=y;
			printf("1 ");
		}
		else{
			y-=x;
			printf("0 ");
		}
	}
	printf("\n");
}

int fun(int x, int y){
	if(x==0 || y==0)
		return -1;
	if(x==y && x>1)
		return -1;
	if(x==1 || y==1)
		return max(x,y)-1;
	if(x>y)
		swap(x,y);
	int temp=fun(y%x,x);
	if(temp!=-1)
		return temp+y/x;
	else
		return -1;
}

int main(){
	scanf("%d",&tc);
	while(tc--){
		scanf("%d",&k);
		ppi best={{0,0},INF};
		int cnt=0;
		for(int x=1; x<k+2 && x<=(k+2-x); x++){
			int y=k+2-x;
			int val=fun(x,y);
//			cerr<<x<<spc<<y<<spc<<val<<endl;
			if(val==-1)
				continue;
			cnt++;
			if(val < best.s2){
				best.f1={x,y};
				best.s2=val;
			}
		}
		printf("%d\n",cnt*2);
		//cerr<<"en kisa: "<<best.s2<<endl;
		ans(best.f1);
	}
	return 0;
}

Compilation message

binary.cpp: In function 'int main()':
binary.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&tc);
  ~~~~~^~~~~~~~~~
binary.cpp:107:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 84 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 380 KB Output is correct
2 Correct 64 ms 380 KB Output is correct
3 Correct 64 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 734 ms 456 KB Output is correct
2 Correct 702 ms 456 KB Output is correct
3 Correct 733 ms 456 KB Output is correct