답안 #160162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160162 2019-10-26T07:56:13 Z combi1k1 Candies (JOI18_candies) C++14
100 / 100
723 ms 27488 KB
#include<bits/stdc++.h>

using namespace std;

#define ll  long long

#define FOR(i,a,b)  for(int i = a ; i <= b ; ++i)

const int   N   = 2e5 + 1;

typedef pair<ll,int>    ii;

set<ii>  S1;
set<int> S2;

ll  a[N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    ll  ans = 0;

    FOR(i,1,n)  {
        cin >> a[i];
        S1.insert({a[i],i});
        S2.insert(i);
    }
    S2.insert(0);
    S2.insert(N);
    FOR(i,1,(n + 1) / 2)    {
        int j = (*--S1.end()).second;

        ans += a[j];
        cout << ans << "\n";

        S1.erase(ii(a[j],j));
        S2.erase(j);

        a[j] = -a[j];

        auto L = S2.upper_bound(j);
        auto R = L--;

        int cnt = 0;

        if (*L >= 1)    {
            a[j] += a[*L];
            S1.erase(ii(a[*L],*L));
            S2.erase(*L);
            cnt++;
        }
        if (*R <= n)    {
            a[j] += a[*R];
            S1.erase(ii(a[*R],*R));
            S2.erase(*R);
            cnt++;
        }
        if (cnt == 2)
            S1.insert(ii(a[j],j)),
            S2.insert(j);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 604 KB Output is correct
6 Correct 4 ms 604 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 5 ms 632 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 4 ms 764 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
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 604 KB Output is correct
6 Correct 4 ms 604 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 5 ms 632 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 4 ms 764 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 27488 KB Output is correct
22 Correct 702 ms 27384 KB Output is correct
23 Correct 723 ms 27440 KB Output is correct
24 Correct 340 ms 27128 KB Output is correct
25 Correct 342 ms 27256 KB Output is correct
26 Correct 335 ms 27248 KB Output is correct
27 Correct 361 ms 27428 KB Output is correct
28 Correct 355 ms 27388 KB Output is correct
29 Correct 351 ms 27276 KB Output is correct
30 Correct 372 ms 27384 KB Output is correct
31 Correct 366 ms 27360 KB Output is correct
32 Correct 370 ms 27256 KB Output is correct
33 Correct 504 ms 27128 KB Output is correct
34 Correct 512 ms 27060 KB Output is correct
35 Correct 500 ms 27092 KB Output is correct
36 Correct 692 ms 27332 KB Output is correct
37 Correct 687 ms 27304 KB Output is correct
38 Correct 702 ms 27384 KB Output is correct
39 Correct 340 ms 27128 KB Output is correct
40 Correct 339 ms 27356 KB Output is correct
41 Correct 356 ms 27144 KB Output is correct
42 Correct 358 ms 27212 KB Output is correct
43 Correct 360 ms 27404 KB Output is correct
44 Correct 346 ms 27384 KB Output is correct
45 Correct 362 ms 27384 KB Output is correct
46 Correct 371 ms 27448 KB Output is correct
47 Correct 367 ms 27400 KB Output is correct
48 Correct 493 ms 27204 KB Output is correct
49 Correct 510 ms 27000 KB Output is correct
50 Correct 509 ms 27292 KB Output is correct