답안 #11576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
11576 2014-12-02T14:17:07 Z gs14004 수열 (BOI14_sequence) C++
67 / 100
1000 ms 2144 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n;
long long res = 1e16, p[17];

void solve(vector<int> bit, long long cb, int depth, int had_zero){
    if(cb >= res) return;
    if(bit.size() == 1){
        int r = bit[0];
        if(r == 0){
            if(cb == 0 || had_zero) cb += p[depth];
        }
        else if(r == 1){
            cb += p[depth] * 10;
        }
        else{
            if(r&1){
                int minima = 1e9;
                for (int i=9; i; i--) {
                    if((r>>i)&1) minima = i;
                }
                for (int i=9; i; i--) {
                    if((r>>i)&1 && i != minima){
                        cb += p[depth] * i;
                        depth++;
                    }
                }
                depth++;
                cb += p[depth] * minima;
            }
            else{
                for (int i=9; i; i--) {
                    if((r>>i)&1){
                        cb += p[depth] * i;
                        depth++;
                    }
                }
            }
        }
        res = min(res,cb);
        return;
    }
    for (int i=0; i<10; i++) {
        int gz = 0;
        vector<int> v2;
        int piv = i;
        v2.push_back(0);
        for (int j=0; j<bit.size(); j++) {
            if(bit[j]&1 && piv == 0) gz = 1;
            v2.back() |= (bit[j] & (~(1<<piv)));
            if(piv == 9 && j != bit.size() - 1){
                v2.push_back(0);
                piv = -1;
            }
            piv++;
        }
        solve(v2,cb + p[depth] * i,depth+1,gz);
    }
}

int main(){
    vector<int> v;
    scanf("%d",&n);
    p[0] = 1;
    for (int i=1; i<17; i++) {
        p[i] = p[i-1] * 10;
    }
    for (int i=0; i<n; i++) {
        int t;
        scanf("%d",&t);
        v.push_back(1<<t);
    }
    solve(v,0,0,0);
    printf("%lld",res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1240 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 0 ms 1240 KB Output is correct
4 Correct 0 ms 1240 KB Output is correct
5 Correct 0 ms 1240 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 0 ms 1240 KB Output is correct
8 Correct 0 ms 1240 KB Output is correct
9 Correct 0 ms 1240 KB Output is correct
10 Correct 4 ms 1240 KB Output is correct
11 Correct 0 ms 1240 KB Output is correct
12 Correct 0 ms 1240 KB Output is correct
13 Correct 0 ms 1240 KB Output is correct
14 Correct 0 ms 1240 KB Output is correct
15 Correct 0 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1240 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 0 ms 1240 KB Output is correct
4 Correct 0 ms 1240 KB Output is correct
5 Correct 0 ms 1240 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 0 ms 1240 KB Output is correct
8 Correct 0 ms 1240 KB Output is correct
9 Correct 0 ms 1240 KB Output is correct
10 Correct 0 ms 1240 KB Output is correct
11 Correct 8 ms 1240 KB Output is correct
12 Correct 4 ms 1240 KB Output is correct
13 Correct 0 ms 1240 KB Output is correct
14 Correct 0 ms 1240 KB Output is correct
15 Correct 0 ms 1240 KB Output is correct
16 Correct 0 ms 1240 KB Output is correct
17 Correct 0 ms 1240 KB Output is correct
18 Correct 0 ms 1240 KB Output is correct
19 Correct 0 ms 1240 KB Output is correct
20 Correct 12 ms 1240 KB Output is correct
21 Correct 4 ms 1240 KB Output is correct
22 Correct 12 ms 1240 KB Output is correct
23 Correct 12 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1240 KB Output is correct
2 Correct 32 ms 1240 KB Output is correct
3 Correct 32 ms 1240 KB Output is correct
4 Correct 24 ms 1240 KB Output is correct
5 Correct 44 ms 1240 KB Output is correct
6 Correct 12 ms 1240 KB Output is correct
7 Correct 124 ms 2024 KB Output is correct
8 Correct 88 ms 1676 KB Output is correct
9 Correct 176 ms 2144 KB Output is correct
10 Correct 176 ms 2144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1240 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 0 ms 1240 KB Output is correct
4 Correct 0 ms 1240 KB Output is correct
5 Correct 272 ms 1668 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 0 ms 1240 KB Output is correct
8 Correct 0 ms 1240 KB Output is correct
9 Correct 0 ms 1240 KB Output is correct
10 Correct 0 ms 1240 KB Output is correct
11 Correct 312 ms 2144 KB Output is correct
12 Correct 180 ms 2144 KB Output is correct
13 Correct 0 ms 1240 KB Output is correct
14 Correct 8 ms 1240 KB Output is correct
15 Correct 4 ms 1240 KB Output is correct
16 Correct 0 ms 1240 KB Output is correct
17 Correct 0 ms 1240 KB Output is correct
18 Correct 0 ms 1240 KB Output is correct
19 Correct 0 ms 1240 KB Output is correct
20 Correct 0 ms 1240 KB Output is correct
21 Correct 0 ms 1240 KB Output is correct
22 Correct 0 ms 1240 KB Output is correct
23 Correct 12 ms 1240 KB Output is correct
24 Correct 4 ms 1240 KB Output is correct
25 Correct 12 ms 1240 KB Output is correct
26 Correct 12 ms 1240 KB Output is correct
27 Correct 32 ms 1240 KB Output is correct
28 Correct 32 ms 1240 KB Output is correct
29 Correct 28 ms 1240 KB Output is correct
30 Correct 44 ms 1240 KB Output is correct
31 Correct 12 ms 1240 KB Output is correct
32 Correct 124 ms 2024 KB Output is correct
33 Correct 92 ms 1676 KB Output is correct
34 Correct 176 ms 2144 KB Output is correct
35 Correct 176 ms 2144 KB Output is correct
36 Correct 696 ms 2036 KB Output is correct
37 Correct 876 ms 2136 KB Output is correct
38 Correct 840 ms 1720 KB Output is correct
39 Execution timed out 1000 ms 2144 KB Program timed out
40 Halted 0 ms 0 KB -