답안 #373394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373394 2021-03-04T12:28:58 Z Hazem 구경하기 (JOI13_watching) C++14
100 / 100
539 ms 16492 KB
#include <bits/stdc++.h>
using namespace std;
 
#define S second
#define F first
#define LL long long
 
const int N = 2e3+10;

LL LINF = 1e18;
LL INF = 1e9;
LL MOD = 1000000009;

LL a[N];
int nxt[N][2],dp[N][N];
int n,p,q;

int solve(int i,int p1){

    if(i==n+1)
        return 0;
    
    if(dp[i][p1]!=-1)
        return dp[i][p1];
    
    dp[i][p1] = solve(nxt[i][1],p1)+1;
    if(p1)dp[i][p1] = min(dp[i][p1],solve(nxt[i][0],p1-1));
    return dp[i][p1];
}

bool ok(LL mid){

    for(int i=1;i<=n;i++){
        nxt[i][0] = lower_bound(a+1,a+n+1,a[i]+mid)-a;
        nxt[i][1] = lower_bound(a+1,a+n+1,a[i]+mid*2)-a;
    }

    memset(dp,-1,sizeof(dp));
    return solve(1,p)<=q;
}

int main(){

    //freopen("out.txt","w",stdout);
    
    scanf("%d%d%d",&n,&p,&q);
    p = min(p,n);
    q = min(q,n);

    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    sort(a+1,a+n+1);

    LL l = 1,r = 1e9;
    while(l<r){
        LL mid = (l+r)/2;
        if(ok(mid))r = mid;
        else l = mid+1;
    }
    printf("%lld\n",l);
}       

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d%d%d",&n,&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
watching.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 16236 KB Output is correct
2 Correct 71 ms 16108 KB Output is correct
3 Correct 69 ms 16236 KB Output is correct
4 Correct 73 ms 16108 KB Output is correct
5 Correct 71 ms 16108 KB Output is correct
6 Correct 72 ms 16236 KB Output is correct
7 Correct 71 ms 16108 KB Output is correct
8 Correct 71 ms 16108 KB Output is correct
9 Correct 73 ms 16236 KB Output is correct
10 Correct 70 ms 16108 KB Output is correct
11 Correct 72 ms 16128 KB Output is correct
12 Correct 69 ms 16108 KB Output is correct
13 Correct 69 ms 16236 KB Output is correct
14 Correct 71 ms 16108 KB Output is correct
15 Correct 70 ms 16236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 16236 KB Output is correct
2 Correct 70 ms 16108 KB Output is correct
3 Correct 473 ms 16364 KB Output is correct
4 Correct 515 ms 16364 KB Output is correct
5 Correct 117 ms 16384 KB Output is correct
6 Correct 515 ms 16364 KB Output is correct
7 Correct 73 ms 16236 KB Output is correct
8 Correct 104 ms 16364 KB Output is correct
9 Correct 199 ms 16492 KB Output is correct
10 Correct 539 ms 16492 KB Output is correct
11 Correct 114 ms 16236 KB Output is correct
12 Correct 405 ms 16364 KB Output is correct
13 Correct 75 ms 16236 KB Output is correct
14 Correct 75 ms 16236 KB Output is correct
15 Correct 74 ms 16236 KB Output is correct