Submission #67157

# Submission time Handle Problem Language Result Execution time Memory
67157 2018-08-13T12:10:05 Z tempytemptemp Hidden Sequence (info1cup18_hidden) C++14
0 / 100
400 ms 308 KB
/*
  Let the good times roll
*/
#include	"grader.h"
#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,ll>
#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 right       ((si<<1)+1)
#define pi          3.141592653589793
#define popcount    __builtin_popcount
#define spc			' '
#define endl		'\n'
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 LIM;

void print(vi v){
	cerr<<"v: ";
	f(i,0,v.size()){
		cerr<<v[i]<<spc;
	}
	cerr<<endl;
}

int oneCount(int n){
	{
		vi v;
		int i;
		bool fl=1;
		for(i=1; fl && i<=LIM; i++){
			v.pb(1);
			if(!isSubsequence(v)){
				fl=0;
				break;
			}
		}
		if(!fl){
			return i-1;
		}
	}
	{
		vi v;
		int i;
		for(i=1; i<=LIM; i++){
			v.pb(0);
			if(!isSubsequence(v)){
				break;
			}
		}
		return n-(i-1);
	}
}

//bool isSubsequence (vector < int > S);
bool is(vi S){
	return isSubsequence(S);
}

set<int> s;

vi vect(int mask, int n){
	vi temp;
	for(int i=0; i<n; i++){
		if(checkbit(mask,i))
			temp.pb(1);
		else
			temp.pb(0);
	}
	return temp;
}

void fun(int mask, int i, int left, int cnt, int n){
	if(i==n){
		if(left!=cnt)
			return;
		s.insert(mask);
		return;
	}
	else{
		fun(mask,i+1,left,cnt,n);
		if(left+1<=cnt){
			fun(setbit(mask,i),i+1,left+1,cnt,n);
		}
	}
}

void createAll(int cnt, int n){
	fun(0,0,0,cnt,n);
}

void killAll(int mask, int LIM, int n){
	vi vm=vect(mask,LIM);
	bool ans=is(vm);
	for(auto x: s){
		vi temp=vect(x,n);
		if(is(temp)!=ans)
			s.erase(x);
	}
}

void fun2(int mask, int i, int n){
	if(i==LIM){
		killAll(mask, LIM, n);
		return;
	}
	else{
		fun2(mask,i+1, n);
		fun2(setbit(mask,i),i+1, n);
	}
}

void eliminate(int n){
	fun2(0,0,n);
}

vector < int > findSequence (int n){
	LIM=n/2+1;
	int cnt=oneCount(n);
//	cerr<<cnt<<endl;
	if(cnt==0){
		vi v;
		f(i,0,n)
			v.pb(0);
		return v;
	}
	else if(cnt==n){
		vi v;
		f(i,0,n)
			v.pb(1);
		return v;
	}
	createAll(cnt, n);
	
	eliminate(n);
	
	return vect(*s.begin(), n);
}

Compilation message

hidden.cpp: In function 'void print(std::vector<int>)':
hidden.cpp:37:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define f(x,y,z)    for(int x=(y); x<(z); x++)
                                     ^
hidden.cpp:73:2: note: in expansion of macro 'f'
  f(i,0,v.size()){
  ^
grader.cpp: In function 'int main()':
grader.cpp:28:43: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     fprintf (fifo_out, "%d\n", ans.size ());
                                ~~~~~~~~~~~^
grader.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<ans.size () && i < N; i++)
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 248 KB Output is not correct: The returned sequence does not match the hidden one
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 308 KB Time limit exceeded
2 Halted 0 ms 0 KB -