답안 #24317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24317 2017-06-04T16:00:52 Z jiaqiyang Sparklers (JOI17_sparklers) C++14
100 / 100
89 ms 7544 KB
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>

typedef long long i64;

const int N = 100000 + 10;
const i64 INF = 1LL << 60;

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

auto calc(std::vector<i64> &cur) {
  const int tot = cur.size();
  std::vector<std::pair<i64, i64>> res;
  for (int i = 0; i < tot;) {
    i64 sum = 0, min = 0;
    int j = i;
    while (j < tot) {
      min = std::min(min, sum += cur[j++]);
      if (sum >= 0) break;
    }
    if (sum >= 0) res.emplace_back(min, sum);
    if (j == tot) cur.erase(cur.begin(), cur.begin() + (sum < 0 ? i : j));
    i = j;
  }
  return res;
}

bool check(std::vector<std::pair<i64, i64>> &u, std::vector<std::pair<i64, i64>> &v, i64 cur) {
  std::reverse(u.begin(), u.end());
  std::reverse(v.begin(), v.end());
  while (!(u.empty() && v.empty())) {
    if (!u.empty() && cur + u.back().first >= 0) {
      cur += u.back().second;
      u.pop_back();
    } else if (!v.empty() && cur + v.back().first >= 0) {
      cur += v.back().second;
      v.pop_back();
    } else {
      return false;
    }
  }
  return true;
}

bool solve(int s) {
  std::vector<i64> a, b;
  for (int i = k; i > 1; --i) a.push_back(2LL * t * s - (x[i] - x[i - 1]));
  for (int i = k; i < n; ++i) b.push_back(2LL * t * s - (x[i + 1] - x[i]));
  i64 temp = std::accumulate(a.begin(), a.end(), std::accumulate(b.begin(), b.end(), 0LL));
  if (temp < 0) return false;
  auto u = calc(a), v = calc(b);
  if (!check(u, v, 0)) return false;
  std::reverse(a.begin(), a.end());
  std::reverse(b.begin(), b.end());
  for (auto &i : a) i = -i;
  for (auto &i : b) i = -i;
  u = calc(a), v = calc(b);
  return check(u, v, temp);
}

int main() {
  scanf("%d%d%d", &n, &k, &t);
  for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
  int l = 0, r = x[n];
  while (l < r) {
    int mid = (l + r) >> 1;
    if (solve(mid)) r = mid; else l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:64:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &n, &k, &t);
                              ^
sparklers.cpp:65:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
                                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1564 KB Output is correct
2 Correct 0 ms 1564 KB Output is correct
3 Correct 0 ms 1564 KB Output is correct
4 Correct 0 ms 1564 KB Output is correct
5 Correct 0 ms 1564 KB Output is correct
6 Correct 0 ms 1564 KB Output is correct
7 Correct 0 ms 1564 KB Output is correct
8 Correct 0 ms 1564 KB Output is correct
9 Correct 0 ms 1564 KB Output is correct
10 Correct 0 ms 1564 KB Output is correct
11 Correct 0 ms 1564 KB Output is correct
12 Correct 0 ms 1564 KB Output is correct
13 Correct 0 ms 1564 KB Output is correct
14 Correct 0 ms 1564 KB Output is correct
15 Correct 0 ms 1564 KB Output is correct
16 Correct 0 ms 1564 KB Output is correct
17 Correct 0 ms 1564 KB Output is correct
18 Correct 0 ms 1564 KB Output is correct
19 Correct 0 ms 1564 KB Output is correct
20 Correct 0 ms 1564 KB Output is correct
21 Correct 0 ms 1564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1564 KB Output is correct
2 Correct 0 ms 1564 KB Output is correct
3 Correct 0 ms 1564 KB Output is correct
4 Correct 0 ms 1564 KB Output is correct
5 Correct 0 ms 1564 KB Output is correct
6 Correct 0 ms 1564 KB Output is correct
7 Correct 0 ms 1564 KB Output is correct
8 Correct 0 ms 1564 KB Output is correct
9 Correct 0 ms 1564 KB Output is correct
10 Correct 0 ms 1564 KB Output is correct
11 Correct 0 ms 1564 KB Output is correct
12 Correct 0 ms 1564 KB Output is correct
13 Correct 0 ms 1564 KB Output is correct
14 Correct 0 ms 1564 KB Output is correct
15 Correct 0 ms 1564 KB Output is correct
16 Correct 0 ms 1564 KB Output is correct
17 Correct 0 ms 1564 KB Output is correct
18 Correct 0 ms 1564 KB Output is correct
19 Correct 0 ms 1564 KB Output is correct
20 Correct 0 ms 1564 KB Output is correct
21 Correct 0 ms 1564 KB Output is correct
22 Correct 0 ms 1564 KB Output is correct
23 Correct 0 ms 1564 KB Output is correct
24 Correct 0 ms 1564 KB Output is correct
25 Correct 0 ms 1564 KB Output is correct
26 Correct 0 ms 1564 KB Output is correct
27 Correct 0 ms 1564 KB Output is correct
28 Correct 0 ms 1564 KB Output is correct
29 Correct 0 ms 1564 KB Output is correct
30 Correct 0 ms 1564 KB Output is correct
31 Correct 0 ms 1564 KB Output is correct
32 Correct 0 ms 1564 KB Output is correct
33 Correct 0 ms 1564 KB Output is correct
34 Correct 0 ms 1564 KB Output is correct
35 Correct 0 ms 1564 KB Output is correct
36 Correct 0 ms 1564 KB Output is correct
37 Correct 0 ms 1564 KB Output is correct
38 Correct 0 ms 1564 KB Output is correct
39 Correct 0 ms 1564 KB Output is correct
40 Correct 0 ms 1564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1564 KB Output is correct
2 Correct 0 ms 1564 KB Output is correct
3 Correct 0 ms 1564 KB Output is correct
4 Correct 0 ms 1564 KB Output is correct
5 Correct 0 ms 1564 KB Output is correct
6 Correct 0 ms 1564 KB Output is correct
7 Correct 0 ms 1564 KB Output is correct
8 Correct 0 ms 1564 KB Output is correct
9 Correct 0 ms 1564 KB Output is correct
10 Correct 0 ms 1564 KB Output is correct
11 Correct 0 ms 1564 KB Output is correct
12 Correct 0 ms 1564 KB Output is correct
13 Correct 0 ms 1564 KB Output is correct
14 Correct 0 ms 1564 KB Output is correct
15 Correct 0 ms 1564 KB Output is correct
16 Correct 0 ms 1564 KB Output is correct
17 Correct 0 ms 1564 KB Output is correct
18 Correct 0 ms 1564 KB Output is correct
19 Correct 0 ms 1564 KB Output is correct
20 Correct 0 ms 1564 KB Output is correct
21 Correct 0 ms 1564 KB Output is correct
22 Correct 0 ms 1564 KB Output is correct
23 Correct 0 ms 1564 KB Output is correct
24 Correct 0 ms 1564 KB Output is correct
25 Correct 0 ms 1564 KB Output is correct
26 Correct 0 ms 1564 KB Output is correct
27 Correct 0 ms 1564 KB Output is correct
28 Correct 0 ms 1564 KB Output is correct
29 Correct 0 ms 1564 KB Output is correct
30 Correct 0 ms 1564 KB Output is correct
31 Correct 0 ms 1564 KB Output is correct
32 Correct 0 ms 1564 KB Output is correct
33 Correct 0 ms 1564 KB Output is correct
34 Correct 0 ms 1564 KB Output is correct
35 Correct 0 ms 1564 KB Output is correct
36 Correct 0 ms 1564 KB Output is correct
37 Correct 0 ms 1564 KB Output is correct
38 Correct 0 ms 1564 KB Output is correct
39 Correct 0 ms 1564 KB Output is correct
40 Correct 0 ms 1564 KB Output is correct
41 Correct 33 ms 4456 KB Output is correct
42 Correct 0 ms 1820 KB Output is correct
43 Correct 9 ms 2344 KB Output is correct
44 Correct 49 ms 7400 KB Output is correct
45 Correct 56 ms 5752 KB Output is correct
46 Correct 66 ms 7544 KB Output is correct
47 Correct 89 ms 7544 KB Output is correct
48 Correct 79 ms 5752 KB Output is correct
49 Correct 43 ms 7288 KB Output is correct
50 Correct 56 ms 5752 KB Output is correct
51 Correct 59 ms 7544 KB Output is correct
52 Correct 63 ms 7272 KB Output is correct
53 Correct 83 ms 7336 KB Output is correct
54 Correct 69 ms 7272 KB Output is correct
55 Correct 46 ms 5752 KB Output is correct
56 Correct 76 ms 7544 KB Output is correct
57 Correct 49 ms 7272 KB Output is correct
58 Correct 63 ms 5752 KB Output is correct
59 Correct 9 ms 1564 KB Output is correct
60 Correct 53 ms 7272 KB Output is correct
61 Correct 46 ms 7272 KB Output is correct
62 Correct 63 ms 7544 KB Output is correct
63 Correct 53 ms 7272 KB Output is correct
64 Correct 69 ms 5752 KB Output is correct
65 Correct 59 ms 5752 KB Output is correct
66 Correct 63 ms 5752 KB Output is correct
67 Correct 63 ms 5752 KB Output is correct
68 Correct 56 ms 7272 KB Output is correct
69 Correct 36 ms 7272 KB Output is correct