답안 #584521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584521 2022-06-27T13:51:00 Z stevancv 구경하기 (JOI13_watching) C++14
100 / 100
672 ms 16224 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, p, q;
    cin >> n >> p >> q;
    smin(p, n);
    smin(q, n);
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    auto Can = [&] (int o) {
        vector<int> x(n + 1), y(n + 1);
        int j = 1;
        for (int i = 1; i <= n; i++) {
            while (a[i] - a[j] >= o) j++;
            x[i] = j;
        }
        j = 1;
        for (int i = 1; i <= n; i++) {
            while (a[i] - a[j] >= 2 * o) j++;
            y[i] = j;
        }
        vector<vector<int>> dp(n + 1, vector<int>(p + 1, 1e9));
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= p; j++) {
                if (j > 0) smin(dp[i][j], dp[x[i] - 1][j - 1]);
                if (dp[y[i] - 1][j] != 1e9) smin(dp[i][j], dp[y[i] - 1][j] + 1);
            }
        }
        for (int j = 0; j <= p; j++) if (dp[n][j] <= q) return true;
        return false;
    };
    int l = 1; int r = 1e9;
    int ans = 1e9;
    while (l <= r) {
        int mid = l + r >> 1;
        if (Can(mid)) {
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << ans << en;
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         int mid = l + r >> 1;
      |                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 489 ms 12288 KB Output is correct
4 Correct 650 ms 16140 KB Output is correct
5 Correct 35 ms 1068 KB Output is correct
6 Correct 672 ms 16224 KB Output is correct
7 Correct 9 ms 468 KB Output is correct
8 Correct 57 ms 1488 KB Output is correct
9 Correct 285 ms 6448 KB Output is correct
10 Correct 653 ms 15368 KB Output is correct
11 Correct 38 ms 1116 KB Output is correct
12 Correct 363 ms 8132 KB Output is correct
13 Correct 7 ms 536 KB Output is correct
14 Correct 9 ms 596 KB Output is correct
15 Correct 11 ms 456 KB Output is correct