답안 #76330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76330 2018-09-12T16:06:32 Z win11905 구경하기 (JOI13_watching) C++11
50 / 100
1000 ms 16888 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e3+5;

int n, p, q;
int A[N];
int dp[N][N];

bool f(int m) {
    memset(dp, 0, sizeof dp);
    for(int i = 0; i <= p; ++i) for(int j = 0; j <= q; ++j) {
        if(i == 0 and j == 0) continue;
        if(i != 0) dp[i][j] = upper_bound(A+1, A+n+1, A[dp[i-1][j]+1] + m - 1) - A - 1;
        if(j != 0) dp[i][j] = max((long int)dp[i][j], upper_bound(A+1, A+n+1, A[dp[i][j-1]+1] + m + m - 1) - A - 1);
        if(dp[i][j] == n) return true;
    }
    return false;
}

int main() {
    scanf("%d %d %d", &n, &p, &q);
    if(p + q >= n) return puts("1"), 0;
    for(int i = 1; i <= n; ++i) scanf("%d", A+i);
    sort(A+1, A+n+1);
    int l = 1, r = 1e9;
    while(l < r) {
        int m = l + r >> 1;
        if(f(m)) r = m;
        else l = m+1;
    }
    return !printf("%d\n", r);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:28:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l + r >> 1;
                 ~~^~~
watching.cpp:22:10: 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:24:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; ++i) scanf("%d", A+i);
                                 ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 16248 KB Output is correct
2 Correct 2 ms 16248 KB Output is correct
3 Correct 44 ms 16492 KB Output is correct
4 Correct 2 ms 16492 KB Output is correct
5 Correct 2 ms 16492 KB Output is correct
6 Correct 2 ms 16492 KB Output is correct
7 Correct 43 ms 16492 KB Output is correct
8 Correct 41 ms 16492 KB Output is correct
9 Correct 42 ms 16604 KB Output is correct
10 Correct 45 ms 16604 KB Output is correct
11 Correct 44 ms 16604 KB Output is correct
12 Correct 48 ms 16604 KB Output is correct
13 Correct 40 ms 16604 KB Output is correct
14 Correct 46 ms 16772 KB Output is correct
15 Correct 45 ms 16772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 16772 KB Output is correct
2 Correct 2 ms 16772 KB Output is correct
3 Correct 2 ms 16772 KB Output is correct
4 Correct 2 ms 16772 KB Output is correct
5 Correct 2 ms 16772 KB Output is correct
6 Correct 2 ms 16772 KB Output is correct
7 Correct 43 ms 16780 KB Output is correct
8 Correct 252 ms 16824 KB Output is correct
9 Correct 192 ms 16848 KB Output is correct
10 Correct 216 ms 16864 KB Output is correct
11 Correct 173 ms 16888 KB Output is correct
12 Execution timed out 1090 ms 16888 KB Time limit exceeded
13 Halted 0 ms 0 KB -