Submission #883199

# Submission time Handle Problem Language Result Execution time Memory
883199 2023-12-04T18:46:41 Z MilosMilutinovic Sparklers (JOI17_sparklers) C++14
100 / 100
37 ms 3928 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;
      } 
    }
    reverse(L.begin(), L.end());
    reverse(R.begin(), R.end());
    {
      if (L[0] < R[0]) {
        return false;
      }
      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;
      }
    }
    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:78:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |     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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 19 ms 2396 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 6 ms 952 KB Output is correct
44 Correct 33 ms 3716 KB Output is correct
45 Correct 29 ms 3112 KB Output is correct
46 Correct 33 ms 3696 KB Output is correct
47 Correct 33 ms 3724 KB Output is correct
48 Correct 29 ms 3216 KB Output is correct
49 Correct 32 ms 3728 KB Output is correct
50 Correct 33 ms 3300 KB Output is correct
51 Correct 33 ms 3924 KB Output is correct
52 Correct 36 ms 3720 KB Output is correct
53 Correct 33 ms 3928 KB Output is correct
54 Correct 34 ms 3528 KB Output is correct
55 Correct 29 ms 3116 KB Output is correct
56 Correct 32 ms 3680 KB Output is correct
57 Correct 32 ms 3632 KB Output is correct
58 Correct 29 ms 3188 KB Output is correct
59 Correct 28 ms 2428 KB Output is correct
60 Correct 33 ms 3508 KB Output is correct
61 Correct 32 ms 3324 KB Output is correct
62 Correct 34 ms 3680 KB Output is correct
63 Correct 31 ms 3480 KB Output is correct
64 Correct 31 ms 3264 KB Output is correct
65 Correct 35 ms 3196 KB Output is correct
66 Correct 37 ms 3156 KB Output is correct
67 Correct 29 ms 3120 KB Output is correct
68 Correct 32 ms 3492 KB Output is correct
69 Correct 31 ms 3472 KB Output is correct