Submission #883198

# Submission time Handle Problem Language Result Execution time Memory
883198 2023-12-04T18:44:16 Z MilosMilutinovic Sparklers (JOI17_sparklers) C++14
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, t;
  cin >> n >> k >> t;
  --k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  auto Check = [&](long long s) {
    if (2 * s * t >= (long long) 1e9) {
      return true;
    }
    vector<long long> L;
    vector<long long> R;
    for (int i = k; i >= 0; i--) {
      L.push_back(x[i] - 2 * s * t * i);
    }
    for (int i = k; i < n; i++) {
      R.push_back(x[i] - 2 * s * t * i);
    }
    int i = 0, j = 0;
    long long mx = L[0];
    long long mn = R[0];
    while (i < (int) L.size() || j < (int) R.size()) {
      if (i < (int) L.size() && L[i] >= mn) {
        mx = max(mx, L[i]);
        i += 1;
        continue;
      }
      if (j < (int) R.size() && R[j] <= mx) {
        mn = min(mn, R[j]);
        j += 1;
        continue;
      }
      break;
    }
    if (i != (int) L.size() || j != (int) R.size()) {
      return false;
    } else {
      return true;
    }
  };
  long long low = 0, high = 1e9, ans = -1;
  while (low <= high) {
    long long mid = low + high >> 1;
    if (Check(mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:51:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |     long long mid = low + high >> 1;
      |                     ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -