Submission #118657

# Submission time Handle Problem Language Result Execution time Memory
118657 2019-06-19T10:32:32 Z imyujin Sequence (BOI14_sequence) C++14
0 / 100
2 ms 384 KB
#include<stdio.h>
#include<vector>

using namespace std;

#define MAXN 100000

const long long LINF=1ll<<60;
int B[MAXN];
int cnt;

long long f(vector<int> v){
	vector<int> vv;
	long long ans=LINF;

	//printf("((((((((\n");
	/*
	for(int i=0; i<v.size(); i++){
		for(int j=9; j>=0; j--) printf("%d", (v[i]>>j)&1);
		printf("\n");
	}
	printf("\n");
	*/

	//if(cnt==100) return ans;
	//cnt++;

	if(v.size()==1){
		//printf(")))))))))\n");
		ans=0;
		int j=1;
		while((v[0]&(1<<j))==0&&j<10) j++;
		if(j==10) return 0;
		else ans=j;
		if(v[0]&1) j*=10;
		for(j++; j<10; j++) if((v[0]&(1<<j))) ans=ans*10+j;
		return ans;
	}
	for(int i=0; i<10; i++){
		bool a=true;
		for(int j=0; j<v.size(); j++) if(v[j]!=(1<<((i+j)%10))&&v[j]!=0) a=false;
		if(a){
			//printf("))))))))\n");
			return i==0?10ll:(long long)i;
		}
	}
	
	for(int i=0; i<10; i++){
		int k=0;
		vv.clear();
		bool a=false;
		for(int j=0; j<v.size(); j++){
			if(j==0||(i+j)%10==0) vv.push_back(0);
			vv[k]|=(v[j]-(v[j]&(1<<((i+j)%10))));
			if(v[j]&(1<<((i+j)%10))) a=true;
			if((i+j)%10==9) k++;
		}
		if(a||vv.size()<v.size())
			ans=min(ans, f(vv)*10+i);
	}
	//printf("))))))))))\n");
	return ans;
}

int main(){
	int K;
	vector<int> v;
	
	scanf("%d", &K);
	for(int i=0; i<K; i++) scanf("%d", B+i);
	
	for(int i=0; i<K; i++) v.push_back(1<<B[i]);
	printf("%lld", f(v));
	return 0;
}

Compilation message

sequence.cpp: In function 'long long int f(std::vector<int>)':
sequence.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<v.size(); j++) if(v[j]!=(1<<((i+j)%10))&&v[j]!=0) a=false;
                ~^~~~~~~~~
sequence.cpp:52:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<v.size(); j++){
                ~^~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &K);
  ~~~~~^~~~~~~~~~
sequence.cpp:70:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<K; i++) scanf("%d", B+i);
                         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -