답안 #22976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22976 2017-04-30T19:12:53 Z Bruteforceman 구경하기 (JOI13_watching) C++11
100 / 100
296 ms 21332 KB
#include <bits/stdc++.h>
using namespace std;
int N, P, Q;
int a[2222];
int big[2222];
int tiny[2222];

int search(int b, int e, int val) {
    if(b == e) {
        return b;
    }
    int m = (b + e) >> 1;
    if(val < a[m]) return search(b, m, val);
    else return search(m + 1, e, val);
}

const int inf = 1e8;

int dp[2222][2222];

bool good(int w) {
    for(int i = 1; i <= N; i++) {
        tiny[i] = search(1, N, a[i] - w) - 1;
        big[i] = search(1, N, a[i] - w - w) - 1;
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= P; j++) {
            dp[i][j] = inf;
            if(j) dp[i][j] = min(dp[i][j], dp[tiny[i]][j - 1]);
            dp[i][j] = min(dp[i][j], dp[big[i]][j] + 1);
        }
    }
    return (dp[N][P] <= Q);
} 

int find(int b, int e) {
    if(b == e) {
        return b;
    }
    int m = (b + e) >> 1;
    if(good(m)) return find(b, m);
    else return find(m + 1, e);
}

int main() {
    scanf("%d %d %d", &N, &P, &Q);
    for(int i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
    }
    sort(a + 1, a + N + 1);
    if(N <= P || N <= Q) {
        printf("%d\n", 1);
        exit(0);
    }
    printf("%d\n", find(1, 1000000000));
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:46:34: 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:48:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 21332 KB Output is correct
2 Correct 0 ms 21332 KB Output is correct
3 Correct 0 ms 21332 KB Output is correct
4 Correct 0 ms 21332 KB Output is correct
5 Correct 0 ms 21332 KB Output is correct
6 Correct 0 ms 21332 KB Output is correct
7 Correct 0 ms 21332 KB Output is correct
8 Correct 0 ms 21332 KB Output is correct
9 Correct 0 ms 21332 KB Output is correct
10 Correct 0 ms 21332 KB Output is correct
11 Correct 0 ms 21332 KB Output is correct
12 Correct 0 ms 21332 KB Output is correct
13 Correct 0 ms 21332 KB Output is correct
14 Correct 0 ms 21332 KB Output is correct
15 Correct 0 ms 21332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21332 KB Output is correct
2 Correct 0 ms 21332 KB Output is correct
3 Correct 219 ms 21332 KB Output is correct
4 Correct 0 ms 21332 KB Output is correct
5 Correct 0 ms 21332 KB Output is correct
6 Correct 0 ms 21332 KB Output is correct
7 Correct 3 ms 21332 KB Output is correct
8 Correct 23 ms 21332 KB Output is correct
9 Correct 113 ms 21332 KB Output is correct
10 Correct 296 ms 21332 KB Output is correct
11 Correct 19 ms 21332 KB Output is correct
12 Correct 139 ms 21332 KB Output is correct
13 Correct 9 ms 21332 KB Output is correct
14 Correct 13 ms 21332 KB Output is correct
15 Correct 6 ms 21332 KB Output is correct