답안 #6161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6161 2014-06-22T05:19:26 Z baneling100 구경하기 (JOI13_watching) C++
100 / 100
92 ms 16752 KB
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0x7fffffff

using namespace std;

int N, P, Q, A[2001], Max, Min=INF, Ans, Small[2001], Big[2001], D[2001][2001];

void input(void)
{
    int i;

    scanf("%d %d %d",&N,&P,&Q);
    if(P+Q>=N)
    {
        printf("1");
        exit(0);
    }
    for(i=1 ; i<=N ; i++)
    {
        scanf("%d",&A[i]);
        if(Max<A[i])
            Max=A[i];
        if(Min>A[i])
            Min=A[i];
    }
    sort(A+1,A+N+1);
}

int OK(int w)
{
    int i, j, x;

    for(i=1 ; i<=N ; i++)
        if(A[i]-A[1]+1>w)
            break;
    x=i-1;
    Small[1]=x;
    for(i=2 ; i<=N ; i++)
    {
        while(x<N && A[x+1]-A[i]+1<=w)
        {
            x++;
        }
        Small[i]=x;
    }
    for(i=1 ; i<=N ; i++)
        if(A[i]-A[1]+1>2*w)
            break;
    x=i-1;
    Big[1]=x;
    for(i=2 ; i<=N ; i++)
    {
        while(x<N && A[x+1]-A[i]+1<=2*w)
        {
            x++;
        }
        Big[i]=x;
    }
    for(i=0 ; i<=P ; i++)
        for(j=0 ; j<=Q ; j++)
        {
            D[i][j]=0;
            if(i>0)
            {
                if(D[i-1][j]==N)
                    D[i][j]=N;
                else
                    if(D[i][j]<Small[D[i-1][j]+1])
                        D[i][j]=Small[D[i-1][j]+1];
            }
            if(j>0)
            {
                if(D[i][j-1]==N)
                    D[i][j]=N;
                else
                    if(D[i][j]<Big[D[i][j-1]+1])
                        D[i][j]=Big[D[i][j-1]+1];
            }
        }
    if(D[P][Q]==N)
        return 1;
    return 0;
}

void process(void)
{
    int left=1, mid, right=Max-Min+1;

    while(left<=right)
    {
        mid=(left+right)/2;
        if(OK(mid))
        {
            Ans=mid;
            right=mid-1;
        }
        else
            left=mid+1;
    }
}

void output(void)
{
    printf("%d",Ans);
}

int main(void)
{
    input();
    process();
    output();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16752 KB Output is correct
2 Correct 0 ms 16752 KB Output is correct
3 Correct 0 ms 16752 KB Output is correct
4 Correct 0 ms 16752 KB Output is correct
5 Correct 0 ms 16752 KB Output is correct
6 Correct 0 ms 16752 KB Output is correct
7 Correct 0 ms 16752 KB Output is correct
8 Correct 0 ms 16752 KB Output is correct
9 Correct 0 ms 16752 KB Output is correct
10 Correct 0 ms 16752 KB Output is correct
11 Correct 0 ms 16752 KB Output is correct
12 Correct 0 ms 16752 KB Output is correct
13 Correct 0 ms 16752 KB Output is correct
14 Correct 0 ms 16752 KB Output is correct
15 Correct 0 ms 16752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16752 KB Output is correct
2 Correct 0 ms 16752 KB Output is correct
3 Correct 0 ms 16752 KB Output is correct
4 Correct 0 ms 16752 KB Output is correct
5 Correct 0 ms 16752 KB Output is correct
6 Correct 0 ms 16752 KB Output is correct
7 Correct 0 ms 16752 KB Output is correct
8 Correct 12 ms 16752 KB Output is correct
9 Correct 8 ms 16752 KB Output is correct
10 Correct 20 ms 16752 KB Output is correct
11 Correct 16 ms 16752 KB Output is correct
12 Correct 92 ms 16752 KB Output is correct
13 Correct 0 ms 16752 KB Output is correct
14 Correct 0 ms 16752 KB Output is correct
15 Correct 0 ms 16752 KB Output is correct