답안 #21043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21043 2017-04-04T05:02:15 Z sbansalcs 구경하기 (JOI13_watching) C++14
0 / 100
0 ms 6540 KB
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 105;
int arr[N];
int dp[N][N][N];
int n,p,q;

bool check(int w)   {
    
    
    for (int i=n+1; i>=0; i--) {
        for (int j=0; j<=p; j++) {
            for (int k=0; k<=p; k++) {
                dp[i][j][k]=0;
                if(i==n+1)  {
                    dp[i][j][k]=1;
                }
                else    {
                    int a;
                    if(j!=0)    {
                        a=arr[i]+w;
                        int lx=i+1,rx=n+1,mx;
                        while (lx<rx) {
                            mx= (lx+rx)/2;
                            if(arr[mx]>=a)  rx=mx;
                            else    lx=mx+1;
                        }
                        dp[i][j][k]|=dp[lx][j-1][k];
                    }
                    if(k!=0 && !dp[i][j][k])    {
                        a=arr[i]+2*w;
                        int lx=i+1,rx=n+1,mx;
                        while (lx<rx) {
                            mx= (lx+rx)/2;
                            if(arr[mx]>=a)  rx=mx;
                            else    lx=mx+1;
                        }
                        dp[i][j][k]|=dp[lx][j][k-1];
                    }
                }
                
            }
        }
    }
    
    
    
    return dp[1][p][q];
}

int main() {
    ;scanf("%d %d %d",&n,&p,&q);
    for (int i=1; i<=n; i++) {
        scanf("%d",arr+i);
    }
    sort(arr+1,arr+1+n);
    arr[n+1]=2e9;
    int lx=1,rx=1e9,mx;
    while (lx<rx) {
        mx=(lx+rx)/2;
        if(check(mx))   rx=mx;
        else    lx=mx+1;
    }
    cout<<lx<<endl;
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:53:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ;scanf("%d %d %d",&n,&p,&q);
                                ^
watching.cpp:55:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",arr+i);
                          ^

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6540 KB Output is correct
2 Correct 0 ms 6540 KB Output is correct
3 Correct 0 ms 6540 KB Output is correct
4 Runtime error 0 ms 6540 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 6540 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -