답안 #492464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492464 2021-12-07T13:04:31 Z ponytail 구경하기 (JOI13_watching) C++17
100 / 100
342 ms 31692 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
void solve(int tc) {
    int N, P, Q;
    cin >> N >> P >> Q;
    P = min(P, N);
    Q = min(Q, N);
    int A[N+1];
    for(int i=1; i<=N; i++) cin >> A[i];
    sort(A+1, A+N+1);
    int lb = 1, rb = 1e9;
    while(lb < rb) {
        int w = (lb+rb) >> 1;
        int dp[P+1][Q+1]; // max index we can reach by P small and Q big
        dp[0][0] = 0;
        int sing[N+1], doub[N+1];
        for(int i=1; i<=N; i++) {
            for(int j=i; j<=N; j++) {
                if(A[j] - A[i] + 1 <= w) sing[i] = j;
                if(A[j] - A[i] + 1 <= 2*w) doub[i] = j;
            }
        }
        int idx = 0;
        for(int i=1; i<=P; i++) {
            dp[i][0] = (idx == N ? N : sing[idx + 1]);
            idx = dp[i][0];
        }
        idx = 0;
        for(int i=1; i<=Q; i++) {
            dp[0][i] = (idx == N ? N : doub[idx + 1]);
            idx = dp[0][i];
        }
        for(int i=1; i<=P; i++) {
            for(int j=1; j<=Q; j++) {
                dp[i][j] = max(
                    (dp[i-1][j] == N ? N : sing[dp[i-1][j] + 1]),
                    (dp[i][j-1] == N ? N : doub[dp[i][j-1] + 1])
                );
            }
        }
        if(dp[P][Q] == N) rb = w;
        else lb = w+1;
    }
    cout << lb << "\n";
}
signed main() {
    int t = 1;
    //cin >> t;
    for(int i=1; i<=t; i++) {
        solve(i);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 308 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 263 ms 17948 KB Output is correct
4 Correct 76 ms 1484 KB Output is correct
5 Correct 78 ms 1484 KB Output is correct
6 Correct 342 ms 31692 KB Output is correct
7 Correct 63 ms 344 KB Output is correct
8 Correct 73 ms 972 KB Output is correct
9 Correct 74 ms 1064 KB Output is correct
10 Correct 80 ms 1612 KB Output is correct
11 Correct 82 ms 1660 KB Output is correct
12 Correct 175 ms 7868 KB Output is correct
13 Correct 58 ms 332 KB Output is correct
14 Correct 60 ms 332 KB Output is correct
15 Correct 60 ms 328 KB Output is correct