답안 #1089010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089010 2024-09-15T18:28:38 Z distiled 구경하기 (JOI13_watching) C++14
0 / 100
2 ms 348 KB
/**
 * Author: distiled
 */
#include<bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include </Users/distiled/codeStuff/templates/debug.h>
#else
#define dbg(x...)
#endif
#define int int64_t


signed main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int n, p, q;
  cin >> n >> p >> q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a.begin() + 1, a.end());
  auto ok = [&] (int w) -> bool {
    const int inf = int(1e9);
    vector<vector<int>> dp(n + 1, vector<int>(min(n + 1, p + 1), inf));
    dp[0] = vector<int>(min(n + 1, p + 1), 0);
    int small = 1, large = 1;
    for (int i = 1; i <= n; i++) {
      while (a[i] - a[small] + 1 > w) {
        small += 1;
      }
      while (a[i] - a[large] + 1 > 2 * w) {
        large += 1;
      }
      for (int j = 1; j <= min(n, p); j++) {
        dp[i][j] = min({dp[i][j], dp[small - 1][j - 1], dp[large - 1][j] + 1});
      }
    }
    bool ok = false;
    for (int j = 1; j <= min(n, p); j++) {
      ok |= dp[n][j] <= q;
    }
    return ok;
  };

  int l = 0, r = int(1e9), ans = 1e9;
  while (l <= r) {
    int m = (l + r) >> 1;
    if (ok(m)) {
      r = m - 1;
      ans = m;
    } else {
      l = m + 1;
    }
  }
  cout << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -