답안 #118688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118688 2019-06-19T11:25:59 Z imyujin 수열 (BOI14_sequence) C++14
100 / 100
202 ms 1784 KB
#include<stdio.h>
#include<vector>

using namespace std;

#define MAXK 100005

const long long LINF=1ll<<58;
int B[MAXK];

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

	bool b=true;
	for(int i=0; i<v.size(); i++) if(v[i]!=0) b=false;
	if(b) return 0;

	if(v.size()==1){
		ans=0;
		int j=1;
		while((v[0]&(1<<j))==0&&j<10) j++;
		if(j==10) return (v[0]&1)==0?0ll:10ll;
		else ans=j;
		if((v[0]&1)!=0) ans*=10;
		for(j++; j<10; j++) if((v[0]&(1<<j))!=0) 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) return i==0&&(v[0]&1)!=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);
	}
	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:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++) if(v[i]!=0) b=false;
               ~^~~~~~~~~
sequence.cpp:31: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:39: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:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &K);
  ~~~~~^~~~~~~~~~
sequence.cpp:56: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);
                         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 128 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 3 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 3 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 4 ms 256 KB Output is correct
23 Correct 3 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 14 ms 512 KB Output is correct
3 Correct 17 ms 512 KB Output is correct
4 Correct 14 ms 512 KB Output is correct
5 Correct 13 ms 384 KB Output is correct
6 Correct 11 ms 384 KB Output is correct
7 Correct 86 ms 1276 KB Output is correct
8 Correct 53 ms 1016 KB Output is correct
9 Correct 120 ms 1656 KB Output is correct
10 Correct 132 ms 1660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 92 ms 1020 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 121 ms 1756 KB Output is correct
12 Correct 117 ms 1784 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 14 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 2 ms 356 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 3 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 14 ms 512 KB Output is correct
28 Correct 14 ms 512 KB Output is correct
29 Correct 14 ms 512 KB Output is correct
30 Correct 14 ms 512 KB Output is correct
31 Correct 12 ms 512 KB Output is correct
32 Correct 90 ms 1404 KB Output is correct
33 Correct 53 ms 1148 KB Output is correct
34 Correct 123 ms 1768 KB Output is correct
35 Correct 119 ms 1720 KB Output is correct
36 Correct 145 ms 1404 KB Output is correct
37 Correct 190 ms 1656 KB Output is correct
38 Correct 115 ms 1268 KB Output is correct
39 Correct 202 ms 1784 KB Output is correct
40 Correct 195 ms 1784 KB Output is correct