답안 #11192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
11192 2014-11-18T14:43:37 Z woqja125 수열 (BOI14_sequence) C++
25 / 100
152 ms 3944 KB
#include<stdio.h>
int d[100001];
long long getAns(int data[], const int n, int depth, bool prevZero)
{
	//printf("%d %d %d \n", n, data[1], data[2]);
    int *arg;
    long long ans = 102345678900000000ll;
    if(n==1 || depth > 6)
    {
        for(int i=2; i<=n; i++) data[1] |= data[i];
        ans = 0;
        int c = 0;
        if(data[1] == 0 && prevZero)
        {
        	return 1;
        }
        else if(data[1] == 0)
        {
        	return 0;
        }
        if(data[1] % 2 == 1)
        {
            if(data[1] == 1) return 10;
            else
            {
                int i;
                for(i=1; i<=9; i++)
                {
                    if(((data[1] >> i) & 1) == 1)
                    {
                        ans = i*10;
                        break;
                    }
                }
                for(i++; i<=9; i++) if(((data[1] >> i) & 1) == 1) ans = ans * 10 + i;
                return ans;
            }
        }
        else
        {
            for(int i=1; i<=9; i++) if(((data[1] >> i) & 1) == 1) ans = ans * 10 + i;
            return ans;
        }
    }
    arg = new int[100001];
    int start = 0;
    for(start = 0; start<=9; start++)
    {
        int fd, N;
        fd = start;
        arg[N = 1] = 0;
        for(int i=1; i<=n; i++)
        {
            if(fd == 10)
            {
                fd = 0;
                arg[++N] = 0;
            }
            arg[N] = arg[N] | (data[i] & (~(1<<fd)) );
            fd++;
        }
        long long l;
        //printf("Call %d %d %d %d %d\n", N, depth+1, arg[1], arg[2], start);
        if(start == 0) l = getAns(arg, N, depth + 1, true);
        else l = getAns(arg, N, depth+1, false);
        //printf("Log %d %d %d %d %lld %d\n", N, depth+1, arg[1], arg[2], l, start);
        if(ans > l*10 + start)
        {
            ans = l*10 + start;
            //printf("Ans %lld\n", ans);
        }
    }
    delete[] arg;
    return ans;
}
int main()
{
    int n, i;
    scanf("%d", &n);
    for(i=1; i<=n; i++)
    {
        scanf("%d", d+i);
    }
    for(i=1; i<=n; i++)
    {
        d[i] = 1<<d[i];
    }
    long long ans = getAns(d, n, 1, true);
    printf("%lld", ans);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3944 KB Output is correct
2 Incorrect 0 ms 3944 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3944 KB Output is correct
2 Incorrect 0 ms 3944 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1596 KB Output is correct
2 Correct 40 ms 3944 KB Output is correct
3 Correct 32 ms 3944 KB Output is correct
4 Correct 40 ms 3944 KB Output is correct
5 Correct 68 ms 3944 KB Output is correct
6 Correct 48 ms 3944 KB Output is correct
7 Correct 108 ms 3944 KB Output is correct
8 Correct 88 ms 3944 KB Output is correct
9 Correct 100 ms 3944 KB Output is correct
10 Correct 152 ms 3944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3944 KB Output is correct
2 Incorrect 0 ms 3944 KB Output isn't correct
3 Halted 0 ms 0 KB -