Submission #145727

# Submission time Handle Problem Language Result Execution time Memory
145727 2019-08-21T00:24:28 Z osaaateiasavtnl Candies (JOI18_candies) C++14
100 / 100
795 ms 25848 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
const int N = 2e5 + 7, INF = 1e18 + 7;
int a[N], d[N];
bool used[N];
struct Comp {
    bool operator () (int i, int j) { return (d[i] > d[j]) || (d[i] == d[j] && i < j); };
};
set <int> s1; set <int, Comp> s2;
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) {
        d[i] = a[i];
        s1.insert(i); s2.insert(i);
    }
    int ans = 0;
    for (int _ = 1; _ <= (n + 1) / 2; ++_) {
        int i = *s2.begin(); s2.erase(s2.begin()); s1.erase(i);
        ans += d[i]; cout << ans << '\n';
        d[i] = -d[i];
        auto r = s1.upper_bound(i);
        bool c = 1;
        if (r != s1.end()) {
            d[i] += d[*r];
            s2.erase(*r); s1.erase(r);
        }
        else c = 0;
        auto l = s1.upper_bound(i);
        if (l != s1.begin()) {
            --l;
            d[i] += d[*l];
            s2.erase(*l); s1.erase(l);
        }
        else c = 0;
        if (c) { s1.insert(i); s2.insert(i); }
        #ifdef HOME
        for (int e : s1) cout << e << ' ' << d[e] << '\n';
        #endif
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 636 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 4 ms 632 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 4 ms 632 KB Output is correct
17 Correct 4 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 636 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 4 ms 632 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 4 ms 632 KB Output is correct
17 Correct 4 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
21 Correct 691 ms 23720 KB Output is correct
22 Correct 747 ms 25796 KB Output is correct
23 Correct 795 ms 25720 KB Output is correct
24 Correct 322 ms 25804 KB Output is correct
25 Correct 330 ms 25536 KB Output is correct
26 Correct 317 ms 25592 KB Output is correct
27 Correct 328 ms 25724 KB Output is correct
28 Correct 329 ms 25620 KB Output is correct
29 Correct 326 ms 25720 KB Output is correct
30 Correct 338 ms 25720 KB Output is correct
31 Correct 342 ms 25720 KB Output is correct
32 Correct 338 ms 25688 KB Output is correct
33 Correct 489 ms 25464 KB Output is correct
34 Correct 482 ms 25412 KB Output is correct
35 Correct 479 ms 25540 KB Output is correct
36 Correct 727 ms 25636 KB Output is correct
37 Correct 674 ms 25832 KB Output is correct
38 Correct 710 ms 25848 KB Output is correct
39 Correct 321 ms 25620 KB Output is correct
40 Correct 321 ms 25464 KB Output is correct
41 Correct 318 ms 25592 KB Output is correct
42 Correct 332 ms 25720 KB Output is correct
43 Correct 328 ms 25812 KB Output is correct
44 Correct 322 ms 25720 KB Output is correct
45 Correct 342 ms 25720 KB Output is correct
46 Correct 340 ms 25724 KB Output is correct
47 Correct 340 ms 25800 KB Output is correct
48 Correct 492 ms 25464 KB Output is correct
49 Correct 547 ms 25648 KB Output is correct
50 Correct 488 ms 25592 KB Output is correct