답안 #11178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
11178 2014-11-18T13:32:10 Z gs13068 수열 (BOI14_sequence) C++
100 / 100
524 ms 2140 KB
#include<cstdio>
#include<vector>

std::vector<int> a;
long long min;

void f(int w,std::vector<int> x,int y,int z,int flag)
{
    if(z>a.size()*10||x.size()==1)
    {
        int i,j=0;
        long long k;
        for(i=0;i<x.size();i++)j|=x[i];
        if(j&1)
        {
            for(i=1;i<10;i++)if((j>>i)&1)break;
            if(i==10)i=1;
            k=i*10;
            while(++i<10)if((j>>i)&1)k=k*10+i;
        }
        else
        {
            k=0;
            for(i=1;i<10;i++)if((j>>i)&1)k=k*10+i;
        }
        if(flag&&!k)k=1;
        if(k*z+y<min)min=k*z+y;
        return;
    }
    int i,j,k;
    std::vector<int> t;
    for(i=0;i<x.size();i++)if(x[i])break;
    if(i==x.size())
    {
        if(flag)y+=z;
        if(y<min)min=y;
        return;
    }

    k=0;
    for(j=0;j<x.size();j++)
    {
        if(!j)k|=x[j];
        else k|=x[j]&~(1<<(j%10));
        if(j%10==9)
        {
            t.push_back(k);
            k=0;
        }
    }
    if(j%10)t.push_back(k);
    f(w+1,t,y,z*10,flag);

    for(i=0;i<10;i++)
    {
        t.clear();

        k=0;
        for(j=0;j<x.size();j++)
        {
            k|=x[j]&~(1<<((i+j)%10));
            if((i+j)%10==9)
            {
                t.push_back(k);
                k=0;
            }
        }
        if((i+j)%10)t.push_back(k);
        f(w+1,t,y+i*z,z*10,i==0);
    }
}

int main()
{
    int i,n,t;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&t);
        a.push_back(1<<t);
    }
    min=1e18;
    f(0,a,0,1,0);
    printf("%lld",min);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 0 ms 1236 KB Output is correct
5 Correct 0 ms 1236 KB Output is correct
6 Correct 0 ms 1236 KB Output is correct
7 Correct 0 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 0 ms 1236 KB Output is correct
10 Correct 0 ms 1236 KB Output is correct
11 Correct 0 ms 1236 KB Output is correct
12 Correct 0 ms 1236 KB Output is correct
13 Correct 0 ms 1236 KB Output is correct
14 Correct 0 ms 1236 KB Output is correct
15 Correct 4 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 0 ms 1236 KB Output is correct
5 Correct 0 ms 1236 KB Output is correct
6 Correct 0 ms 1236 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Correct 0 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 0 ms 1236 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 0 ms 1236 KB Output is correct
13 Correct 0 ms 1236 KB Output is correct
14 Correct 0 ms 1236 KB Output is correct
15 Correct 0 ms 1236 KB Output is correct
16 Correct 4 ms 1236 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 0 ms 1236 KB Output is correct
19 Correct 0 ms 1236 KB Output is correct
20 Correct 0 ms 1236 KB Output is correct
21 Correct 0 ms 1236 KB Output is correct
22 Correct 4 ms 1236 KB Output is correct
23 Correct 4 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 44 ms 1236 KB Output is correct
3 Correct 44 ms 1236 KB Output is correct
4 Correct 44 ms 1236 KB Output is correct
5 Correct 48 ms 1236 KB Output is correct
6 Correct 24 ms 1236 KB Output is correct
7 Correct 208 ms 2020 KB Output is correct
8 Correct 124 ms 1672 KB Output is correct
9 Correct 504 ms 2140 KB Output is correct
10 Correct 504 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 0 ms 1236 KB Output is correct
5 Correct 132 ms 1664 KB Output is correct
6 Correct 0 ms 1236 KB Output is correct
7 Correct 0 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 0 ms 1236 KB Output is correct
10 Correct 4 ms 1236 KB Output is correct
11 Correct 476 ms 2140 KB Output is correct
12 Correct 492 ms 2140 KB Output is correct
13 Correct 0 ms 1236 KB Output is correct
14 Correct 0 ms 1236 KB Output is correct
15 Correct 0 ms 1236 KB Output is correct
16 Correct 0 ms 1236 KB Output is correct
17 Correct 0 ms 1236 KB Output is correct
18 Correct 0 ms 1236 KB Output is correct
19 Correct 4 ms 1236 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
21 Correct 0 ms 1236 KB Output is correct
22 Correct 0 ms 1236 KB Output is correct
23 Correct 0 ms 1236 KB Output is correct
24 Correct 0 ms 1236 KB Output is correct
25 Correct 4 ms 1236 KB Output is correct
26 Correct 4 ms 1236 KB Output is correct
27 Correct 52 ms 1236 KB Output is correct
28 Correct 52 ms 1236 KB Output is correct
29 Correct 44 ms 1236 KB Output is correct
30 Correct 44 ms 1236 KB Output is correct
31 Correct 16 ms 1236 KB Output is correct
32 Correct 184 ms 2020 KB Output is correct
33 Correct 128 ms 1672 KB Output is correct
34 Correct 508 ms 2140 KB Output is correct
35 Correct 524 ms 2140 KB Output is correct
36 Correct 184 ms 2032 KB Output is correct
37 Correct 248 ms 2132 KB Output is correct
38 Correct 160 ms 1716 KB Output is correct
39 Correct 480 ms 2140 KB Output is correct
40 Correct 476 ms 2140 KB Output is correct