Submission #243971

# Submission time Handle Problem Language Result Execution time Memory
243971 2020-07-02T12:18:01 Z TadijaSebez Sequence (BOI14_sequence) C++11
100 / 100
241 ms 1520 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll Solve(vector<int> v,int sub=0){
	if(v.size()==1){
		if(v[0]==0)return 0;
		ll ans=0;
		for(int i=1;i<=9;i++){
			if(v[0]>>i&1){
				ans=ans*10+i;
				if(v[0]&1)ans*=10,v[0]--;
			}
		}
		if(v[0]&1)ans=10;
		return ans;
	}else{
		ll ans=1e18;
		for(int las=0;las<=9-sub;las++){
			vector<int> tmp;
			int all=0,zr=0;
			for(int i=0,j=las;i<v.size();i++,j=(j+1)%10){
				if(i&&!j)tmp.pb(all),all=0;
				if(!j&&(v[i]&1))zr=1;
				all|=v[i]&(~(1<<j));
			}
			tmp.pb(all);
			ll now=Solve(tmp,v.size()<=2&&las==9)*10+las;
			if(zr&&!now)now=10;
			ans=min(ans,now);
		}
		return ans;
	}
}
int main(){
	int n;scanf("%i",&n);
	vector<int> v;
	for(int i=1,j;i<=n;i++)scanf("%i",&j),v.pb(1<<j);
	printf("%lld\n",Solve(v));
	return 0;
}

Compilation message

sequence.cpp: In function 'long long int Solve(std::vector<int>, int)':
sequence.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0,j=las;i<v.size();i++,j=(j+1)%10){
                      ~^~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:36:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n;scanf("%i",&n);
        ~~~~~^~~~~~~~~
sequence.cpp:38:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,j;i<=n;i++)scanf("%i",&j),v.pb(1<<j);
                         ~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 7 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 256 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 7 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 29 ms 384 KB Output is correct
3 Correct 32 ms 384 KB Output is correct
4 Correct 31 ms 384 KB Output is correct
5 Correct 29 ms 384 KB Output is correct
6 Correct 21 ms 384 KB Output is correct
7 Correct 153 ms 1148 KB Output is correct
8 Correct 121 ms 892 KB Output is correct
9 Correct 217 ms 1400 KB Output is correct
10 Correct 218 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 115 ms 1012 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 224 ms 1400 KB Output is correct
12 Correct 215 ms 1400 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 7 ms 256 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 7 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 8 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 7 ms 384 KB Output is correct
26 Correct 7 ms 384 KB Output is correct
27 Correct 29 ms 384 KB Output is correct
28 Correct 29 ms 384 KB Output is correct
29 Correct 28 ms 384 KB Output is correct
30 Correct 28 ms 384 KB Output is correct
31 Correct 21 ms 384 KB Output is correct
32 Correct 152 ms 1148 KB Output is correct
33 Correct 113 ms 892 KB Output is correct
34 Correct 220 ms 1520 KB Output is correct
35 Correct 216 ms 1520 KB Output is correct
36 Correct 177 ms 1148 KB Output is correct
37 Correct 240 ms 1400 KB Output is correct
38 Correct 155 ms 1020 KB Output is correct
39 Correct 240 ms 1520 KB Output is correct
40 Correct 241 ms 1400 KB Output is correct