답안 #227207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
227207 2020-04-26T13:51:03 Z nvmdava Candies (JOI18_candies) C++17
100 / 100
603 ms 29008 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 200005
const ll MOD = 1'000'000'007;
const int INF = 0x3f3f3f3f;

set<pair<ll, ll> > a, p;
ll ans = 0;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    for(int x, i = 1; i <= n; ++i){
        cin>>x;
        x *= -1;
        a.insert({i, x});
        p.insert({x, i});
    }
    a.insert({0, 1'000'000'000'000'000'000});
    a.insert({n + 1, 1'000'000'000'000'000'000});
    p.insert({1'000'000'000'000'000'000, 0});
    p.insert({1'000'000'000'000'000'000, n + 1});
    for(int i = 1; i <= (n + 1) / 2; ++i){
        pair<ll, ll> x = *p.begin();
        swap(x.ff, x.ss);
        ans -= x.ss;
        auto it = a.find(x);

        x.ss = 0;
        --it;
        x.ss += it -> ss;
        p.erase({it -> ss, it -> ff});
        it = a.erase(it);
        x.ss -= it -> ss;
        p.erase({it -> ss, it -> ff});
        it = a.erase(it);
        x.ss += it -> ss;
        p.erase({it -> ss, it -> ff});
        it = a.erase(it);

        a.insert(x);
        p.insert({x.ss, x.ff});
        cout<<ans<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 7 ms 640 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 7 ms 640 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 616 KB Output is correct
21 Correct 569 ms 28792 KB Output is correct
22 Correct 567 ms 28792 KB Output is correct
23 Correct 581 ms 28792 KB Output is correct
24 Correct 268 ms 28664 KB Output is correct
25 Correct 264 ms 28732 KB Output is correct
26 Correct 278 ms 28680 KB Output is correct
27 Correct 306 ms 28920 KB Output is correct
28 Correct 276 ms 28792 KB Output is correct
29 Correct 283 ms 28920 KB Output is correct
30 Correct 303 ms 28796 KB Output is correct
31 Correct 297 ms 28792 KB Output is correct
32 Correct 300 ms 28792 KB Output is correct
33 Correct 410 ms 28664 KB Output is correct
34 Correct 405 ms 28664 KB Output is correct
35 Correct 430 ms 28792 KB Output is correct
36 Correct 594 ms 28920 KB Output is correct
37 Correct 602 ms 28792 KB Output is correct
38 Correct 603 ms 29008 KB Output is correct
39 Correct 287 ms 28668 KB Output is correct
40 Correct 271 ms 28664 KB Output is correct
41 Correct 273 ms 28664 KB Output is correct
42 Correct 281 ms 28792 KB Output is correct
43 Correct 289 ms 28796 KB Output is correct
44 Correct 298 ms 28792 KB Output is correct
45 Correct 302 ms 28920 KB Output is correct
46 Correct 289 ms 28792 KB Output is correct
47 Correct 309 ms 28920 KB Output is correct
48 Correct 452 ms 28792 KB Output is correct
49 Correct 416 ms 28664 KB Output is correct
50 Correct 419 ms 28664 KB Output is correct