답안 #540390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540390 2022-03-20T09:20:52 Z krit3379 구경하기 (JOI13_watching) C++17
50 / 100
1000 ms 11732 KB
#include<bits/stdc++.h>
using namespace std;
#define N 2005

long long a[N],dp[N][N],l,r,mid,ans;

int main(){
    int n,i,j,p,q;
    scanf("%d %d %d",&n,&p,&q);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    a[n+1]=1e18;
    sort(a+1,a+n+1);
    if(p+q>=n){printf("1");return 0;}
    l=1,r=1e9;
    while(l<=r){
        mid=(l+r)/2;
        for(i=0;i<=p;i++)for(j=0;j<=q;j++)dp[i][j]=0;
        dp[0][0]=1;
        for(i=1;i<=p;i++)dp[i][0]=upper_bound(a+1,a+n+1,a[dp[i-1][0]]+mid-1)-a;
        for(i=1;i<=q;i++)dp[0][i]=upper_bound(a+1,a+n+1,a[dp[0][i-1]]+2*mid-1)-a;
        for(i=1;i<=p;i++){
            for(j=1;j<=q;j++){
                int pos1=upper_bound(a+1,a+n+1,a[dp[i][j-1]]+2*mid-1)-a;
                int pos2=upper_bound(a+1,a+n+1,a[dp[i-1][j]]+mid-1)-a;
                dp[i][j]=max(pos1,pos2);

            }
        }
        if(dp[p][q]==n+1)ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d %d",&n,&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     for(i=1;i<=n;i++)scanf("%lld",&a[i]);
      |                      ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 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 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 169 ms 1552 KB Output is correct
9 Correct 139 ms 4084 KB Output is correct
10 Correct 216 ms 9300 KB Output is correct
11 Correct 279 ms 1740 KB Output is correct
12 Execution timed out 1079 ms 11732 KB Time limit exceeded
13 Halted 0 ms 0 KB -