Submission #1043916

# Submission time Handle Problem Language Result Execution time Memory
1043916 2024-08-05T04:08:34 Z juicy Sparklers (JOI17_sparklers) C++17
100 / 100
51 ms 3716 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;

int n, k, t;
int x[N];

bool reach(vector<long long> &lt, vector<long long> &rt) {
  if (lt[0] < rt[0]) {
    return 0;
  }
  array<int, 2> l{}, r{};
  bool chg = 1;
  while (chg) {
    chg = 0;
    while (l[0] + 1 < lt.size() && lt[l[0] + 1] >= rt[r[1]]) {
      ++l[0];
      chg = 1;
      if (lt[l[0]] >= lt[l[1]]) {
        l[1] = l[0];
      }
    }
    while (r[0] + 1 < rt.size() && rt[r[0] + 1] <= lt[l[1]]) {
      ++r[0];
      chg = 1;
      if (rt[r[0]] <= rt[r[1]]) {
        r[1] = r[0];
      }
    }
  }
  return l[0] == lt.size() - 1 && r[0] == rt.size() - 1;
}

bool check(int s) {
  vector<long long> lt, rt;
  for (int i = k; i > 0; --i) {
    lt.push_back(x[i] - (long long) 2 * s * i * t);
  }
  for (int i = k; i <= n; ++i) {
    rt.push_back(x[i] - (long long) 2 * s * i * t);
  }
  if (!reach(lt, rt)) {
    return 0;
  }
  reverse(lt.begin(), lt.end());
  reverse(rt.begin(), rt.end());
  return reach(lt, rt);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> k >> t;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
  }
  int l = 0, r = 1e9, res = r;
  while (l <= r) {
    int md = (l + r) / 2;
    if (check(md)) {
      res = md;
      r = md - 1;
    } else {
      l = md + 1;
    }
  }
  cout << res;
  return 0;
}

Compilation message

sparklers.cpp: In function 'bool reach(std::vector<long long int>&, std::vector<long long int>&)':
sparklers.cpp:24:21: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     while (l[0] + 1 < lt.size() && lt[l[0] + 1] >= rt[r[1]]) {
sparklers.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     while (r[0] + 1 < rt.size() && rt[r[0] + 1] <= lt[l[1]]) {
sparklers.cpp:39:15: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   return l[0] == lt.size() - 1 && r[0] == rt.size() - 1;
sparklers.cpp:39:40: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   return l[0] == lt.size() - 1 && r[0] == rt.size() - 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 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 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 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 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 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 348 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 408 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 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 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 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 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 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 348 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 408 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 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 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 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 30 ms 2384 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 7 ms 968 KB Output is correct
44 Correct 41 ms 3692 KB Output is correct
45 Correct 36 ms 3188 KB Output is correct
46 Correct 42 ms 3704 KB Output is correct
47 Correct 44 ms 3672 KB Output is correct
48 Correct 35 ms 3116 KB Output is correct
49 Correct 43 ms 3708 KB Output is correct
50 Correct 36 ms 3192 KB Output is correct
51 Correct 51 ms 3716 KB Output is correct
52 Correct 41 ms 3512 KB Output is correct
53 Correct 40 ms 3684 KB Output is correct
54 Correct 41 ms 3528 KB Output is correct
55 Correct 35 ms 3188 KB Output is correct
56 Correct 41 ms 3660 KB Output is correct
57 Correct 40 ms 3604 KB Output is correct
58 Correct 34 ms 3188 KB Output is correct
59 Correct 34 ms 2392 KB Output is correct
60 Correct 42 ms 3508 KB Output is correct
61 Correct 45 ms 3600 KB Output is correct
62 Correct 43 ms 3660 KB Output is correct
63 Correct 41 ms 3480 KB Output is correct
64 Correct 34 ms 3176 KB Output is correct
65 Correct 35 ms 3196 KB Output is correct
66 Correct 36 ms 3172 KB Output is correct
67 Correct 34 ms 3120 KB Output is correct
68 Correct 49 ms 3708 KB Output is correct
69 Correct 40 ms 3536 KB Output is correct