답안 #749211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749211 2023-05-27T14:42:51 Z stevancv Candies (JOI18_candies) C++14
100 / 100
654 ms 30436 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const ll linf = 1e18;
set<pair<ll, ll>> a, b;
void Add(ll x, ll y) {
    a.insert({x, y});
    b.insert({y, x});
}
void Rem(ll x, ll y) {
    a.erase({x, y});
    b.erase({y, x});
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        Add(i, v[i]);
    }
    Add(-1, -linf); Add(n, -linf);
    ll ans = 0;
    for (int i = 0; i < (n + 1) / 2; i++) {
        auto it = b.rbegin();
        auto o = *it;
        ans += o.first;
        cout << ans << en;
        auto itt = a.lower_bound({o.second, o.first});
        auto x = *prev(itt);
        auto y = *itt;
        auto z = *next(itt);
        Rem(x.first, x.second);
        Rem(y.first, y.second);
        Rem(z.first, z.second);
        Add(y.first, x.second + z.second - y.second);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 708 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 708 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 617 ms 30340 KB Output is correct
22 Correct 654 ms 30360 KB Output is correct
23 Correct 641 ms 30292 KB Output is correct
24 Correct 255 ms 30108 KB Output is correct
25 Correct 268 ms 30312 KB Output is correct
26 Correct 270 ms 30184 KB Output is correct
27 Correct 264 ms 30436 KB Output is correct
28 Correct 260 ms 30284 KB Output is correct
29 Correct 309 ms 30356 KB Output is correct
30 Correct 271 ms 30312 KB Output is correct
31 Correct 315 ms 30380 KB Output is correct
32 Correct 278 ms 30364 KB Output is correct
33 Correct 374 ms 30276 KB Output is correct
34 Correct 419 ms 30052 KB Output is correct
35 Correct 365 ms 30096 KB Output is correct
36 Correct 594 ms 30320 KB Output is correct
37 Correct 590 ms 30424 KB Output is correct
38 Correct 561 ms 30316 KB Output is correct
39 Correct 258 ms 30144 KB Output is correct
40 Correct 251 ms 30148 KB Output is correct
41 Correct 251 ms 30152 KB Output is correct
42 Correct 256 ms 30316 KB Output is correct
43 Correct 264 ms 30312 KB Output is correct
44 Correct 252 ms 30368 KB Output is correct
45 Correct 286 ms 30372 KB Output is correct
46 Correct 258 ms 30284 KB Output is correct
47 Correct 280 ms 30284 KB Output is correct
48 Correct 399 ms 30148 KB Output is correct
49 Correct 393 ms 30100 KB Output is correct
50 Correct 393 ms 30052 KB Output is correct