답안 #81590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81590 2018-10-25T13:11:14 Z chelly 구경하기 (JOI13_watching) C++11
100 / 100
645 ms 1032 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int dp[2][MAXN], N, P, Q;
vector<int> events;
int next (int i, int w){
    if (i>=N) return N;
    int lo = i, hi = N;
    while (lo<hi){
        int mid = (lo+hi+1)/2;
        if (events[mid-1]-events[i-1]+1<=w) lo = mid;
        else hi = mid-1;
    }
    return lo;
}
bool check (int w){
    memset (dp, 0, sizeof dp);
    for (int i = 0; i<=P; i++){
        for (int j = 0; j<=Q; j++){
            if (i>0) dp[i%2][j] = max(dp[i%2][j], next(dp[(i-1)%2][j]+1, w));
            if (j>0) dp[i%2][j] = max(dp[i%2][j], next(dp[i%2][j-1]+1, 2*w));
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            if (dp[i%2][j]==N) return 1;
        }
    }
    return 0;
}
int main(){
    scanf("%d%d%d", &N, &P, &Q);
    P = min(N, P);
    Q = min(N, Q);
    for (int i = 0, a; i<N; i++){
        scanf("%d", &a);
        events.push_back(a);
    }
    sort (events.begin(), events.end());
    int lo = 1, hi = 1000000000;
    while (lo<hi){
        int mid = (lo+hi)/2;
        //cout<<lo<<" "<<hi<<" "<<mid<<endl;
        if (check(mid)) hi = mid;
        else lo = mid+1;
    }
    printf("%d\n", lo);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:29: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:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 4 ms 636 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 772 KB Output is correct
15 Correct 3 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 772 KB Output is correct
2 Correct 2 ms 828 KB Output is correct
3 Correct 307 ms 828 KB Output is correct
4 Correct 120 ms 828 KB Output is correct
5 Correct 3 ms 828 KB Output is correct
6 Correct 4 ms 828 KB Output is correct
7 Correct 3 ms 848 KB Output is correct
8 Correct 110 ms 996 KB Output is correct
9 Correct 113 ms 1016 KB Output is correct
10 Correct 144 ms 1016 KB Output is correct
11 Correct 61 ms 1016 KB Output is correct
12 Correct 645 ms 1032 KB Output is correct
13 Correct 3 ms 1032 KB Output is correct
14 Correct 3 ms 1032 KB Output is correct
15 Correct 3 ms 1032 KB Output is correct