답안 #647468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647468 2022-10-02T16:45:51 Z PoonYaPat 구경하기 (JOI13_watching) C++14
100 / 100
131 ms 16076 KB
#include <bits/stdc++.h>
using namespace std;

int n,sm,bg,a[2001];
int dp[2001][2001];

bool check(int w) {

    for (int i=0; i<n; ++i) {
        int preb=(int)(upper_bound(a,a+n,a[i]-2*w)-a)-1;
        int pres=(int)(upper_bound(a,a+n,a[i]-w)-a)-1;

        if (pres!=-1) dp[i][0]=dp[pres][0]+1;
        else dp[i][0]=1;

        for (int j=1; j<=bg; ++j) {
            if (preb==-1) dp[i][j]=0;
            else dp[i][j]=min(dp[preb][j-1],dp[pres][j]+1);
        }
    }

    if (dp[n-1][bg]<=sm) return true;
    else return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>sm>>bg;
    for (int i=0; i<n; ++i) cin>>a[i];
    sort(a,a+n);

    if (sm+bg>=n) {
        cout<<1;
        return 0;
    }

    int l=1,r=1e9,ans=1e9;
    while (l<=r) {
        int mid=(l+r)/2;
        if (check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 708 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8276 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 8 ms 8404 KB Output is correct
8 Correct 58 ms 14164 KB Output is correct
9 Correct 16 ms 9356 KB Output is correct
10 Correct 14 ms 9080 KB Output is correct
11 Correct 131 ms 16076 KB Output is correct
12 Correct 75 ms 16000 KB Output is correct
13 Correct 10 ms 8404 KB Output is correct
14 Correct 10 ms 8404 KB Output is correct
15 Correct 12 ms 8508 KB Output is correct