답안 #44051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44051 2018-03-29T12:59:12 Z wxh010910 Candies (JOI18_candies) C++17
100 / 100
164 ms 9276 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 200005;
const LL inf = 1LL << 60;

priority_queue <pair <LL, int>> q;
int n, nxt[N], pre[N];
LL ans, a[N];

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n);
  for (int i = 1; i <= n; ++i) {
    Read(a[i]), pre[i] = i - 1, nxt[i] = i + 1;
    q.push(mp(a[i], i));
  }
  nxt[n] = 0;
  for (int i = 1; i <= n + 1 >> 1; ++i) {
    for (; q.top().X != a[q.top().Y]; q.pop());
    int x = q.top().Y, l = pre[x], r = nxt[x];
    printf("%lld\n", ans += a[x]), q.pop();
    pre[nxt[x] = nxt[r]] = x, nxt[pre[x] = pre[l]] = x;
    a[x] = l && r ? max(-inf, a[l] + a[r] - a[x]) : -inf, a[l] = a[r] = -inf;
    q.push(mp(a[x], x));
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:58:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   for (int i = 1; i <= n + 1 >> 1; ++i) {
                        ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 708 KB Output is correct
4 Correct 3 ms 708 KB Output is correct
5 Correct 3 ms 708 KB Output is correct
6 Correct 3 ms 708 KB Output is correct
7 Correct 3 ms 708 KB Output is correct
8 Correct 3 ms 708 KB Output is correct
9 Correct 3 ms 708 KB Output is correct
10 Correct 3 ms 708 KB Output is correct
11 Correct 3 ms 708 KB Output is correct
12 Correct 3 ms 708 KB Output is correct
13 Correct 2 ms 708 KB Output is correct
14 Correct 3 ms 708 KB Output is correct
15 Correct 3 ms 708 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
19 Correct 3 ms 848 KB Output is correct
20 Correct 3 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 708 KB Output is correct
4 Correct 3 ms 708 KB Output is correct
5 Correct 3 ms 708 KB Output is correct
6 Correct 3 ms 708 KB Output is correct
7 Correct 3 ms 708 KB Output is correct
8 Correct 3 ms 708 KB Output is correct
9 Correct 3 ms 708 KB Output is correct
10 Correct 3 ms 708 KB Output is correct
11 Correct 3 ms 708 KB Output is correct
12 Correct 3 ms 708 KB Output is correct
13 Correct 2 ms 708 KB Output is correct
14 Correct 3 ms 708 KB Output is correct
15 Correct 3 ms 708 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
19 Correct 3 ms 848 KB Output is correct
20 Correct 3 ms 848 KB Output is correct
21 Correct 140 ms 8996 KB Output is correct
22 Correct 121 ms 9056 KB Output is correct
23 Correct 125 ms 9244 KB Output is correct
24 Correct 96 ms 9244 KB Output is correct
25 Correct 95 ms 9244 KB Output is correct
26 Correct 96 ms 9244 KB Output is correct
27 Correct 115 ms 9244 KB Output is correct
28 Correct 114 ms 9244 KB Output is correct
29 Correct 125 ms 9244 KB Output is correct
30 Correct 115 ms 9244 KB Output is correct
31 Correct 118 ms 9244 KB Output is correct
32 Correct 122 ms 9244 KB Output is correct
33 Correct 118 ms 9244 KB Output is correct
34 Correct 119 ms 9244 KB Output is correct
35 Correct 118 ms 9244 KB Output is correct
36 Correct 127 ms 9244 KB Output is correct
37 Correct 131 ms 9244 KB Output is correct
38 Correct 135 ms 9244 KB Output is correct
39 Correct 97 ms 9244 KB Output is correct
40 Correct 94 ms 9244 KB Output is correct
41 Correct 93 ms 9244 KB Output is correct
42 Correct 122 ms 9244 KB Output is correct
43 Correct 113 ms 9244 KB Output is correct
44 Correct 112 ms 9244 KB Output is correct
45 Correct 164 ms 9244 KB Output is correct
46 Correct 122 ms 9276 KB Output is correct
47 Correct 116 ms 9276 KB Output is correct
48 Correct 119 ms 9276 KB Output is correct
49 Correct 117 ms 9276 KB Output is correct
50 Correct 117 ms 9276 KB Output is correct