# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
347272 | 2021-01-12T13:23:07 Z | CaroLinda | Candies (JOI18_candies) | C++14 | 712 ms | 27584 KB |
#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(),x.end() #define sz(x) (int)(x.size() ) const int MAXN = 2e5+10 ; using namespace std ; int N ; ll valCandies[MAXN] ; set< pair<ll,int> > candies ; set<int> orderCandies ; int main() { scanf("%d", &N ) ; for(int i = 1 ; i <= N ; i++ ) { scanf("%lld", &valCandies[i] ) ; candies.insert(make_pair(-valCandies[i], i) ); orderCandies.insert(i) ; } ll ans = 0LL ; for(int i = 1 ; i <= ( (N+1)>>1 ) ; i++ ) { ll val = -candies.begin()->first ; int idx = candies.begin()->second ; candies.erase( candies.begin() ) ; auto itPrev = orderCandies.find(idx) ; int idxPrev = -1 ; int idxNxt = -1 ; if( itPrev != orderCandies.begin() ) { itPrev-- ; idxPrev = *itPrev ; candies.erase( candies.find(make_pair(-valCandies[idxPrev] , idxPrev ) ) ) ; orderCandies.erase( itPrev ) ; } auto itNxt = orderCandies.find(idx) ; itNxt++ ; if(itNxt != orderCandies.end() ) { idxNxt = *itNxt ; candies.erase( candies.find(make_pair(-valCandies[idxNxt], idxNxt) ) ) ; orderCandies.erase( itNxt ) ; } if(idxNxt != -1 && idxPrev != -1 ) { valCandies[idxPrev] += valCandies[idxNxt] ; valCandies[idxPrev] -= val ; candies.insert(make_pair(-valCandies[idxPrev] , idxPrev ) ) ; orderCandies.insert( idxPrev ) ; } orderCandies.erase( orderCandies.find(idx) ) ; printf("%lld\n", ans += val ) ; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 620 KB | Output is correct |
2 | Correct | 3 ms | 620 KB | Output is correct |
3 | Correct | 3 ms | 620 KB | Output is correct |
4 | Correct | 3 ms | 620 KB | Output is correct |
5 | Correct | 4 ms | 620 KB | Output is correct |
6 | Correct | 3 ms | 620 KB | Output is correct |
7 | Correct | 3 ms | 620 KB | Output is correct |
8 | Correct | 3 ms | 620 KB | Output is correct |
9 | Correct | 2 ms | 620 KB | Output is correct |
10 | Correct | 2 ms | 648 KB | Output is correct |
11 | Correct | 3 ms | 620 KB | Output is correct |
12 | Correct | 3 ms | 620 KB | Output is correct |
13 | Correct | 3 ms | 620 KB | Output is correct |
14 | Correct | 3 ms | 636 KB | Output is correct |
15 | Correct | 3 ms | 620 KB | Output is correct |
16 | Correct | 3 ms | 620 KB | Output is correct |
17 | Correct | 3 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 3 ms | 624 KB | Output is correct |
20 | Correct | 2 ms | 620 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 620 KB | Output is correct |
2 | Correct | 3 ms | 620 KB | Output is correct |
3 | Correct | 3 ms | 620 KB | Output is correct |
4 | Correct | 3 ms | 620 KB | Output is correct |
5 | Correct | 4 ms | 620 KB | Output is correct |
6 | Correct | 3 ms | 620 KB | Output is correct |
7 | Correct | 3 ms | 620 KB | Output is correct |
8 | Correct | 3 ms | 620 KB | Output is correct |
9 | Correct | 2 ms | 620 KB | Output is correct |
10 | Correct | 2 ms | 648 KB | Output is correct |
11 | Correct | 3 ms | 620 KB | Output is correct |
12 | Correct | 3 ms | 620 KB | Output is correct |
13 | Correct | 3 ms | 620 KB | Output is correct |
14 | Correct | 3 ms | 636 KB | Output is correct |
15 | Correct | 3 ms | 620 KB | Output is correct |
16 | Correct | 3 ms | 620 KB | Output is correct |
17 | Correct | 3 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 3 ms | 624 KB | Output is correct |
20 | Correct | 2 ms | 620 KB | Output is correct |
21 | Correct | 705 ms | 27216 KB | Output is correct |
22 | Correct | 712 ms | 27264 KB | Output is correct |
23 | Correct | 695 ms | 27568 KB | Output is correct |
24 | Correct | 282 ms | 27116 KB | Output is correct |
25 | Correct | 290 ms | 27116 KB | Output is correct |
26 | Correct | 327 ms | 27116 KB | Output is correct |
27 | Correct | 293 ms | 27372 KB | Output is correct |
28 | Correct | 299 ms | 27584 KB | Output is correct |
29 | Correct | 317 ms | 27308 KB | Output is correct |
30 | Correct | 306 ms | 27372 KB | Output is correct |
31 | Correct | 313 ms | 27244 KB | Output is correct |
32 | Correct | 311 ms | 27244 KB | Output is correct |
33 | Correct | 463 ms | 26988 KB | Output is correct |
34 | Correct | 464 ms | 27116 KB | Output is correct |
35 | Correct | 496 ms | 27116 KB | Output is correct |
36 | Correct | 712 ms | 27372 KB | Output is correct |
37 | Correct | 689 ms | 27244 KB | Output is correct |
38 | Correct | 694 ms | 27244 KB | Output is correct |
39 | Correct | 275 ms | 27116 KB | Output is correct |
40 | Correct | 277 ms | 27116 KB | Output is correct |
41 | Correct | 281 ms | 27116 KB | Output is correct |
42 | Correct | 293 ms | 27244 KB | Output is correct |
43 | Correct | 289 ms | 27244 KB | Output is correct |
44 | Correct | 289 ms | 27244 KB | Output is correct |
45 | Correct | 308 ms | 27244 KB | Output is correct |
46 | Correct | 310 ms | 27244 KB | Output is correct |
47 | Correct | 311 ms | 27244 KB | Output is correct |
48 | Correct | 456 ms | 27116 KB | Output is correct |
49 | Correct | 470 ms | 27244 KB | Output is correct |
50 | Correct | 466 ms | 26988 KB | Output is correct |