Submission #118713

# Submission time Handle Problem Language Result Execution time Memory
118713 2019-06-19T13:52:12 Z sebinkim Sequence (BOI14_sequence) C++14
100 / 100
100 ms 1784 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
ll n;
 
ll f(vector <ll> &X, ll d, bool z)
{
	if(d > 14) return -1;
	
	vector <ll> Y;
	ll i, j, k, y, ret = 1e18;
	
	if(X.size() == 1){
		if(z && X[0] == 0) return 1;
		else if(z && X[0] == 1) return 10;
		
		ret = 0;
		
		for(i=1; i<10; i++){
			if(X[0] & (1ll << i)){
				ret = ret * 10 + i;
				if(X[0] & 1ll){
					ret *= 10; X[0] -= 1;
				}
			}
		}
		
		return ret;
	}
	
	for(i=0; i<10; i++){
		Y.clear(); y = 0;
		
		for(j=0, k=i; j<X.size(); j++, k=++k%10){
			if(k == 0 && j) Y.push_back(y), y = 0;
			
			if(X[j] & (1ll << k)) y |= X[j] - (1ll << k);
			else y |= X[j];
		}
		
		Y.push_back(y);
		
		if(X == Y) continue;
		
		k = f(Y, d + 1, Y[0] != 0 || (z && i == 0)) * 10 + i;
		if(k >= 0) ret = min(ret, k);
	}
	
	return ret;
}
 
int main()
{
	vector <ll> X;
	ll i, x;
	
	scanf("%lld", &n);
	
	for(i=0; i<n; i++){
		scanf("%lld", &x);
		X.push_back(1ll << x);
	}
	
	printf("%lld\n", f(X, 1, 1));
	
	return 0;
}

Compilation message

sequence.cpp: In function 'll f(std::vector<long long int>&, ll, bool)':
sequence.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0, k=i; j<X.size(); j++, k=++k%10){
                 ~^~~~~~~~~
sequence.cpp:37:35: warning: operation on 'k' may be undefined [-Wsequence-point]
   for(j=0, k=i; j<X.size(); j++, k=++k%10){
                                  ~^~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
sequence.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &x);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 356 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 3 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 11 ms 512 KB Output is correct
4 Correct 9 ms 512 KB Output is correct
5 Correct 9 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 43 ms 1656 KB Output is correct
8 Correct 39 ms 1020 KB Output is correct
9 Correct 58 ms 1656 KB Output is correct
10 Correct 59 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 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 48 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 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 59 ms 1784 KB Output is correct
12 Correct 85 ms 1656 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 11 ms 512 KB Output is correct
28 Correct 11 ms 540 KB Output is correct
29 Correct 9 ms 512 KB Output is correct
30 Correct 10 ms 512 KB Output is correct
31 Correct 7 ms 512 KB Output is correct
32 Correct 42 ms 1528 KB Output is correct
33 Correct 39 ms 1020 KB Output is correct
34 Correct 57 ms 1656 KB Output is correct
35 Correct 58 ms 1656 KB Output is correct
36 Correct 73 ms 1656 KB Output is correct
37 Correct 96 ms 1656 KB Output is correct
38 Correct 59 ms 1052 KB Output is correct
39 Correct 100 ms 1680 KB Output is correct
40 Correct 99 ms 1656 KB Output is correct