Submission #764648

# Submission time Handle Problem Language Result Execution time Memory
764648 2023-06-23T17:44:48 Z ind1v Watching (JOI13_watching) C++11
50 / 100
1000 ms 16216 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2005;

int n, p, q;
long long a[N];
int dp[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> p >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (p + q >= n) {
    cout << 1;
    exit(0);
  }
  sort(a + 1, a + n + 1);
  a[0] = numeric_limits<long long>::min();
  int l = 1, r = 1000000000, ans = -1;
  while (l <= r) {
    int m = l + r >> 1;
    memset(dp, 0x3f, sizeof(dp));
    for (int j = 0; j <= q; j++) {
      dp[0][j] = 0;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= q; j++) {
        int prv = upper_bound(a, a + n + 1, a[i] - m) - a;
        dp[i][j] = min(dp[i][j], 1 + dp[prv - 1][j]);
        if (j > 0) {
          prv = upper_bound(a, a + n + 1, a[i] - 2 * m) - a;
          dp[i][j] = min(dp[i][j], dp[prv - 1][j - 1]);
        }
      }
    }
    if (dp[n][q] <= p) {
      ans = m;
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  cout << ans;
  return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:26:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |     int m = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 15956 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 27 ms 16060 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 30 ms 15992 KB Output is correct
8 Correct 28 ms 16040 KB Output is correct
9 Correct 28 ms 15956 KB Output is correct
10 Correct 29 ms 15956 KB Output is correct
11 Correct 29 ms 15944 KB Output is correct
12 Correct 34 ms 16060 KB Output is correct
13 Correct 28 ms 15956 KB Output is correct
14 Correct 26 ms 15956 KB Output is correct
15 Correct 27 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 16084 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 53 ms 16080 KB Output is correct
8 Execution timed out 1073 ms 16216 KB Time limit exceeded
9 Halted 0 ms 0 KB -