답안 #118518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118518 2019-06-19T06:48:24 Z 김세빈(#2898) 수열 (BOI14_sequence) C++14
100 / 100
131 ms 1656 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);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 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 384 KB Output is correct
9 Correct 2 ms 256 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 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 372 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 3 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 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 10 ms 512 KB Output is correct
3 Correct 10 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 41 ms 1528 KB Output is correct
8 Correct 38 ms 1020 KB Output is correct
9 Correct 57 ms 1528 KB Output is correct
10 Correct 57 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 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 384 KB Output is correct
5 Correct 51 ms 1020 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 60 ms 1656 KB Output is correct
12 Correct 112 ms 1656 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 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 256 KB Output is correct
18 Correct 2 ms 256 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 256 KB Output is correct
22 Correct 3 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 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 640 KB Output is correct
28 Correct 12 ms 640 KB Output is correct
29 Correct 10 ms 512 KB Output is correct
30 Correct 9 ms 640 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 41 ms 1656 KB Output is correct
33 Correct 39 ms 1020 KB Output is correct
34 Correct 57 ms 1656 KB Output is correct
35 Correct 56 ms 1656 KB Output is correct
36 Correct 73 ms 1656 KB Output is correct
37 Correct 97 ms 1656 KB Output is correct
38 Correct 61 ms 1148 KB Output is correct
39 Correct 131 ms 1656 KB Output is correct
40 Correct 102 ms 1656 KB Output is correct