Submission #67049

# Submission time Handle Problem Language Result Execution time Memory
67049 2018-08-13T09:19:46 Z tempytemptemp Hidden Sequence (info1cup18_hidden) C++14
15 / 100
400 ms 500 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);

vi glob;
vi ans;

vi glob2;

bool pos;

void fun2(int i, int cnt){
	if(!pos)
		return;
	if(i==glob.size()){
		if(cnt>LIM){
			return;
		}
		if(cnt==0){
			return;
		}
		if(!isSubsequence(glob2)){
			pos=0;
			return;
		}
		else{
			return;
		}
	}
	else{
		fun2(i+1,cnt);
		if(!pos)
			return;
		if(cnt+1<=LIM){
			glob2.pb(glob[i]);
			fun2(i+1,cnt+1);
			if(!pos)
				return;
			glob2.pop_back();
		}
	}
}

bool check2(){
	pos=1;
	glob2.clear();
	fun2(0,0);
	if(pos){
		return true;
	}
	else{
		return false;
	}
}

bool check(){
	f(i,0,glob.size()){
		int j=i+LIM-1;
		if(j>=glob.size())
			break;
		vi v;
		f(k,i,j+1){
			v.pb(glob[k]);
			if(!isSubsequence(v))
				return false;
		}
	}
	if(check2()){
		return true;
	}
	return false;
}

bool fun(int i, int left, int cnt, int n){
	if(i==n){
		if(left!=cnt){
			return false;
		}
		if(check()){
			ans=glob;
			return true;
		}
		else{
			return false;
		}
	}
	else{
		if(fun(i+1,left,cnt,n)){
			return true;
		}
		else{
			if(left+1<=cnt){
				glob[i]=1;
				if(fun(i+1,left+1,cnt,n)){
					return true;
				}
				else{
					glob[i]=0;
					return false;
				}
			}
			else{
				return false;
			}
		}
	}
}

vector < int > findSequence (int n){
	LIM=3*n/4+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;
	}
	f(i,0,n)
		glob.pb(0);
	fun(0,0,cnt,n);
	return ans;
}

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()){
  ^
hidden.cpp: In function 'void fun2(int, int)':
hidden.cpp:120:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(i==glob.size()){
     ~^~~~~~~~~~~~~
hidden.cpp: In function 'bool check()':
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:162:2: note: in expansion of macro 'f'
  f(i,0,glob.size()){
  ^
hidden.cpp:164:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(j>=glob.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 Partially correct 4 ms 248 KB Output is partially correct: Maximum length of a query = 7
2 Partially correct 15 ms 308 KB Output is partially correct: Maximum length of a query = 8
3 Partially correct 9 ms 472 KB Output is partially correct: Maximum length of a query = 7
4 Partially correct 6 ms 472 KB Output is partially correct: Maximum length of a query = 7
5 Partially correct 6 ms 472 KB Output is partially correct: Maximum length of a query = 6
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 500 KB Time limit exceeded
2 Halted 0 ms 0 KB -