답안 #118722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118722 2019-06-19T14:13:16 Z onjo0127 수열 (BOI14_sequence) C++11
0 / 100
5 ms 512 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;
		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(i && !k) N.push_back(y);
			y |= (S[j] & (~(1 << k)));
		}
		N.push_back(y);
		long long tmp = solve(N, dep + 1, N[0] != 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, 0));
	return 0;
}

Compilation message

sequence.cpp: In function 'long long int solve(std::vector<int>, int, bool)':
sequence.cpp:19: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:32: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:34:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int foo; scanf("%d",&foo);
            ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 5 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 5 ms 300 KB Output isn't correct
3 Halted 0 ms 0 KB -