답안 #361194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361194 2021-01-28T14:25:19 Z andreicroitoru 구경하기 (JOI13_watching) C++17
100 / 100
280 ms 16128 KB
#include <bits/stdc++.h>

using namespace std;

const int nax=2001;
int n,p,q;
long long v[2001];
int dp[2001][2001];
bool check(long long w)
{
    if(w<=0)
    {
        return false;
    }
    memset(dp,0,sizeof(dp));
    for(int i=0; i<n; i++)
    {
        int ppp=0;
        while(i-ppp>=0 && v[i]-w+1LL<=v[i-ppp])
        {
            ppp++;
        }
        int pp=0;
        while(i-pp>=0 && v[i]-2LL*w+1<=v[i-pp])
        {
            pp++;
        }
        for(int j=0; j<=q; j++)
        {
            if(i-ppp<0)dp[i][j]=1;
            else dp[i][j]=dp[i-ppp][j]+1;
            if(j!=0)
            {
                if(i-pp<0)
                {
                    dp[i][j]=0;
                }
                else
                {
                    dp[i][j]=min(dp[i][j],dp[i-pp][j-1]);
                }
            }
        }
    }
    return dp[n-1][q]<=p;
}

int main()
{
    cin>>n>>p>>q;
    if(p+q>=n)
    {
        cout<<1<<'\n';
        return 0;
    }
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    sort(v,v+n);
    long long x=-1,i;
    for(i=1e9; i>=1LL; i/=2LL)
    {
        while(!check(x+i))
        {
            x+=i;
        }
    }
    cout<<x+1<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 15980 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 95 ms 15980 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 103 ms 16128 KB Output is correct
8 Correct 98 ms 16108 KB Output is correct
9 Correct 95 ms 15980 KB Output is correct
10 Correct 100 ms 16108 KB Output is correct
11 Correct 83 ms 15980 KB Output is correct
12 Correct 80 ms 15980 KB Output is correct
13 Correct 82 ms 15980 KB Output is correct
14 Correct 96 ms 15980 KB Output is correct
15 Correct 87 ms 16108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 15980 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 143 ms 15980 KB Output is correct
8 Correct 204 ms 15980 KB Output is correct
9 Correct 127 ms 15980 KB Output is correct
10 Correct 99 ms 16108 KB Output is correct
11 Correct 280 ms 16108 KB Output is correct
12 Correct 209 ms 15980 KB Output is correct
13 Correct 130 ms 15980 KB Output is correct
14 Correct 126 ms 15980 KB Output is correct
15 Correct 130 ms 16108 KB Output is correct