답안 #118717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118717 2019-06-19T14:03:53 Z songc 수열 (BOI14_sequence) C++14
25 / 100
114 ms 1244 KB
#include <bits/stdc++.h>
#define INF 1234567890123456ll
using namespace std;
typedef long long LL;

int N;

LL f(vector<int> A, int lv){
    if (lv > 15) return INF;
    LL ans = INF;
    if (A.size() == 1){
        LL ret=0;
        if (A[0] == 1) return 10;
        for (int i=1; i<10; i++) if (A[0] & (1<<i)){
            ret = ret*10 + i;
            if (A[0] & 1) ret = ret*10, A[0] ^= 1;
        }
        return ret;
    }

    for (int i=0; i<10; i++){
        vector<int> B((i+A.size()+9)/10);
        for (int j=0; j<(int)A.size(); j++) B[(i+j)/10] |= A[j] & ~(1<<((i+j)%10));
        if (A == B) continue;
        LL ret = f(B, lv+1);
        if (ret == INF) continue;
        if (ret == 0 && i == 0) ans = min(ans, 10ll);
        else ans = min(ans, ret*10 + i);
    }
    return ans;
}

int main(){
    scanf("%d", &N);
    vector<int> A(N);
    for (int i=0; i<N; i++) {
        scanf("%d", &A[i]);
        A[i] = 1 << A[i];
    }
    printf("%lld\n", f(A, 1));
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
sequence.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 3 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 3 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 21 ms 384 KB Output is correct
3 Correct 23 ms 384 KB Output is correct
4 Correct 21 ms 512 KB Output is correct
5 Correct 29 ms 384 KB Output is correct
6 Correct 11 ms 384 KB Output is correct
7 Correct 77 ms 896 KB Output is correct
8 Correct 82 ms 888 KB Output is correct
9 Correct 114 ms 1244 KB Output is correct
10 Correct 107 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 3 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -