Submission #118735

# Submission time Handle Problem Language Result Execution time Memory
118735 2019-06-19T14:20:50 Z onjo0127 Sequence (BOI14_sequence) C++11
100 / 100
879 ms 1392 KB
#include <bits/stdc++.h>
using namespace std;

long long solve(vector<int> S, int dep, bool lzn) {
	if(dep >= 15) return -1;
	if(S.size() == 1) {
		if(lzn) {
			if(S[0] == 0) return 1;
			if(S[0] == 1) return 10;
		}
		long long ret = 0;
		for(int i=1; i<10; i++) if(S[0] & (1 << i)) {
			ret *= 10, ret += i;
			if(S[0] & 1) ret *= 10, --S[0];
		}
		return ret;
	}
	long long ret = 1LL * 1e18;
	for(int i=0; i<10; i++) {
		vector<int> N; int y = 0;
		for(int j=0, k=i; j<S.size(); j++, k++, k%=10) {
			if(j && !k) N.push_back(y), y = 0;
			y |= (S[j] & (~(1 << k)));
		}
		N.push_back(y);
		long long tmp = solve(N, dep + 1, N[0] != 0 || (lzn && i == 0));
		if(tmp != -1LL) ret = min(ret, tmp * 10 + i);
	}
	return ret;
}

int main() {
	vector<int> S;
	int K; scanf("%d",&K);
	for(int i=0; i<K; i++) {
		int foo; scanf("%d",&foo);
		S.push_back(1 << foo);
	}
	printf("%lld", solve(S, 1, 1));
	return 0;
}

Compilation message

sequence.cpp: In function 'long long int solve(std::vector<int>, int, bool)':
sequence.cpp:21:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0, k=i; j<S.size(); j++, k++, k%=10) {
                     ~^~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int K; scanf("%d",&K);
         ~~~~~^~~~~~~~~
sequence.cpp:36:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int foo; scanf("%d",&foo);
            ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 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 3 ms 256 KB Output is correct
8 Correct 12 ms 384 KB Output is correct
9 Correct 2 ms 356 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 11 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 13 ms 256 KB Output is correct
15 Correct 13 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 13 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 13 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 13 ms 384 KB Output is correct
12 Correct 11 ms 256 KB Output is correct
13 Correct 10 ms 256 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 13 ms 384 KB Output is correct
17 Correct 13 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 12 ms 384 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 12 ms 384 KB Output is correct
23 Correct 13 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 104 ms 504 KB Output is correct
3 Correct 103 ms 472 KB Output is correct
4 Correct 99 ms 504 KB Output is correct
5 Correct 102 ms 504 KB Output is correct
6 Correct 78 ms 428 KB Output is correct
7 Correct 591 ms 1020 KB Output is correct
8 Correct 398 ms 884 KB Output is correct
9 Correct 848 ms 1320 KB Output is correct
10 Correct 851 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 389 ms 764 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 13 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 869 ms 1280 KB Output is correct
12 Correct 867 ms 1364 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 13 ms 256 KB Output is correct
15 Correct 11 ms 384 KB Output is correct
16 Correct 10 ms 372 KB Output is correct
17 Correct 3 ms 256 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 13 ms 384 KB Output is correct
20 Correct 13 ms 384 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 12 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 13 ms 384 KB Output is correct
26 Correct 13 ms 384 KB Output is correct
27 Correct 105 ms 504 KB Output is correct
28 Correct 104 ms 432 KB Output is correct
29 Correct 97 ms 412 KB Output is correct
30 Correct 98 ms 512 KB Output is correct
31 Correct 76 ms 384 KB Output is correct
32 Correct 593 ms 1020 KB Output is correct
33 Correct 396 ms 852 KB Output is correct
34 Correct 841 ms 1280 KB Output is correct
35 Correct 844 ms 1392 KB Output is correct
36 Correct 631 ms 1020 KB Output is correct
37 Correct 843 ms 1264 KB Output is correct
38 Correct 502 ms 892 KB Output is correct
39 Correct 867 ms 1388 KB Output is correct
40 Correct 879 ms 1392 KB Output is correct