답안 #281279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281279 2020-08-23T04:15:29 Z Autoratch 구경하기 (JOI13_watching) C++14
100 / 100
429 ms 16252 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2001;

int n,p,q;
int a[N];
long long l = 1,r = 1e9;
int dp[N][N],sm[N],bg[N];

bool solve(int x)
{
    int now = 1;
    for(int i = 1;i <= n;i++) 
    {
        while(now<n and a[now+1]-a[i]+1<=x) now++;
        sm[i] = now;
    }
    now = 1;
    for(int i = 1;i <= n;i++)
    {
        while(now<n and a[now+1]-a[i]+1<=x*2) now++;
        bg[i] = now;
    }
    for(int i = 0;i <= n;i++) for(int j = 0;j <= n;j++)
    {
        dp[i][j] = 0;
        if(i) dp[i][j] = max(dp[i][j],sm[dp[i-1][j]+1]);
        if(j) dp[i][j] = max(dp[i][j],bg[dp[i][j-1]+1]);
        if(dp[i][j]==n and i<=p and j<=q) return true;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> p >> q;
    for(int i = 1;i <= n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    while(l<r)
    {
        long long m = (l+r)/2LL;
        if(solve(m)) r = m;
        else l = m+1;
    }
    cout << l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 16120 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 48 ms 4088 KB Output is correct
4 Correct 350 ms 15384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 429 ms 16120 KB Output is correct
8 Correct 159 ms 16252 KB Output is correct
9 Correct 312 ms 16120 KB Output is correct
10 Correct 368 ms 15992 KB Output is correct
11 Correct 65 ms 15992 KB Output is correct
12 Correct 183 ms 15992 KB Output is correct
13 Correct 215 ms 16120 KB Output is correct
14 Correct 358 ms 15992 KB Output is correct
15 Correct 309 ms 16120 KB Output is correct