답안 #673355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673355 2022-12-20T10:07:49 Z Hanksburger Candies (JOI18_candies) C++17
100 / 100
421 ms 19500 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
set<pair<ll, pair<ll, ll> > > q;
ll a[200005], b[200005];
set<pair<ll, ll> > s;
ll f(ll l, ll r)
{
    return b[r]-b[l-2]-b[r+1]+(l<3?0:b[l-3]);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, k=0;
    cin >> n;
    for (ll i=1; i<=n; i++)
    {
        cin >> a[i];
        b[i]=(i<2?0:b[i-2])+a[i];
        q.insert({-a[i], {i, i}});
    }
    for (ll i=1; i<=(n+1)/2; i++)
    {
        cout << (k-=(*q.begin()).first) << '\n';
        ll l=(*q.begin()).second.first, r=(*q.begin()).second.second;
        if (l<r)
            s.erase({l+1, r-1});
        q.erase(q.begin());
        q.erase({-a[l-1], {l-1, l-1}});
        q.erase({-a[r+1], {r+1, r+1}});
        auto it=s.lower_bound({l, r});
        if (it!=s.begin() && (*prev(it)).second==l-2)
        {
            ll L=(*prev(it)).first, R=(*prev(it)).second;
            s.erase({L, R});
            s.erase({l, r});
            if (L>1 && R<n)
                q.erase({f(L, R), {L-1, R+1}});
            l=L;
        }
        if (it!=s.end() && (*it).first==r+2)
        {
            ll L=(*it).first, R=(*it).second;
            s.erase({L, R});
            s.erase({l, r});
            if (L>1 && R<n)
                q.erase({f(L, R), {L-1, R+1}});
            r=R;
        }
        s.insert({l, r});
        if (l>1 && r<n)
            q.insert({f(l, r), {l-1, r+1}});
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 420 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 476 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 420 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 476 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 398 ms 19392 KB Output is correct
22 Correct 418 ms 19448 KB Output is correct
23 Correct 388 ms 19460 KB Output is correct
24 Correct 158 ms 19160 KB Output is correct
25 Correct 159 ms 19240 KB Output is correct
26 Correct 164 ms 19380 KB Output is correct
27 Correct 179 ms 19372 KB Output is correct
28 Correct 177 ms 19308 KB Output is correct
29 Correct 178 ms 19448 KB Output is correct
30 Correct 181 ms 19392 KB Output is correct
31 Correct 183 ms 19376 KB Output is correct
32 Correct 182 ms 19500 KB Output is correct
33 Correct 257 ms 19156 KB Output is correct
34 Correct 256 ms 19148 KB Output is correct
35 Correct 269 ms 19168 KB Output is correct
36 Correct 380 ms 19276 KB Output is correct
37 Correct 421 ms 19276 KB Output is correct
38 Correct 386 ms 19376 KB Output is correct
39 Correct 153 ms 19148 KB Output is correct
40 Correct 157 ms 19144 KB Output is correct
41 Correct 160 ms 19348 KB Output is correct
42 Correct 183 ms 19300 KB Output is correct
43 Correct 173 ms 19344 KB Output is correct
44 Correct 182 ms 19416 KB Output is correct
45 Correct 184 ms 19292 KB Output is correct
46 Correct 180 ms 19404 KB Output is correct
47 Correct 190 ms 19444 KB Output is correct
48 Correct 256 ms 19132 KB Output is correct
49 Correct 262 ms 19100 KB Output is correct
50 Correct 257 ms 19192 KB Output is correct