# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
61713 |
2018-07-26T12:02:42 Z |
mAng0 |
Candies (JOI18_candies) |
C++17 |
|
687 ms |
26840 KB |
#include<bits/stdc++.h>
using namespace std;
using interval = pair<int, int>;
#define s first
#define e second
map<interval, long long> mp;
using qtype = pair<long long, interval>;
priority_queue<qtype> pq;
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
long long x;
scanf("%lld",&x);
mp[{i, i}] = x;
pq.push({x, {i, i}});
}
long long ans = 0;
for(int i=0;i<(n+1)/2;i++){
while(true){
auto it = mp.find(pq.top().second);
if(it == mp.end()){
pq.pop();
}else{
if((*it).second == pq.top().first){
break;
}else{
pq.pop();
}
}
}
//printf("hi: %d - %d, %lld\n", pq.top().second.s, pq.top().second.e, pq.top().first);
qtype top = pq.top(); pq.pop();
ans += top.first;
interval tt = top.second;
interval newtt = tt;
long long newval = -top.first;
long long vall = top.first;
auto pit = mp.find(tt);
auto nit = pit; nit++;
int all_ok = 0;
if(pit != mp.begin()){
pit--;
all_ok++;
newtt.s = (*pit).first.s;
newval += (*pit).second;
//printf("del: %d - %d, %lld\n", (*pit).first.s, (*pit).first.e, (*pit).second);
mp.erase(pit);
}
if(nit != mp.end()){
all_ok++;
newtt.e = (*nit).first.e;
newval += (*nit).second;
//printf("del: %d - %d, %lld\n", (*nit).first.s, (*nit).first.e, (*nit).second);
mp.erase(nit);
}
//printf("del: %d - %d, %lld\n", tt.s, tt.e, vall);
mp.erase(tt);
if(all_ok == 2){
mp[newtt] = newval;
//printf("add: %d - %d, %lld\n", newtt.s, newtt.e, newval);
pq.push({newval, newtt});
}
printf("%lld\n", ans);
}
}
Compilation message
candies.cpp: In function 'int main()':
candies.cpp:42:19: warning: unused variable 'vall' [-Wunused-variable]
long long vall = top.first;
^~~~
candies.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
candies.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&x);
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
612 KB |
Output is correct |
3 |
Correct |
6 ms |
612 KB |
Output is correct |
4 |
Correct |
6 ms |
808 KB |
Output is correct |
5 |
Correct |
7 ms |
808 KB |
Output is correct |
6 |
Correct |
6 ms |
812 KB |
Output is correct |
7 |
Correct |
6 ms |
860 KB |
Output is correct |
8 |
Correct |
5 ms |
884 KB |
Output is correct |
9 |
Correct |
6 ms |
900 KB |
Output is correct |
10 |
Correct |
6 ms |
1052 KB |
Output is correct |
11 |
Correct |
6 ms |
1052 KB |
Output is correct |
12 |
Correct |
5 ms |
1052 KB |
Output is correct |
13 |
Correct |
5 ms |
1052 KB |
Output is correct |
14 |
Correct |
5 ms |
1052 KB |
Output is correct |
15 |
Correct |
5 ms |
1072 KB |
Output is correct |
16 |
Correct |
6 ms |
1092 KB |
Output is correct |
17 |
Correct |
6 ms |
1240 KB |
Output is correct |
18 |
Correct |
5 ms |
1240 KB |
Output is correct |
19 |
Correct |
5 ms |
1240 KB |
Output is correct |
20 |
Correct |
5 ms |
1240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
612 KB |
Output is correct |
3 |
Correct |
6 ms |
612 KB |
Output is correct |
4 |
Correct |
6 ms |
808 KB |
Output is correct |
5 |
Correct |
7 ms |
808 KB |
Output is correct |
6 |
Correct |
6 ms |
812 KB |
Output is correct |
7 |
Correct |
6 ms |
860 KB |
Output is correct |
8 |
Correct |
5 ms |
884 KB |
Output is correct |
9 |
Correct |
6 ms |
900 KB |
Output is correct |
10 |
Correct |
6 ms |
1052 KB |
Output is correct |
11 |
Correct |
6 ms |
1052 KB |
Output is correct |
12 |
Correct |
5 ms |
1052 KB |
Output is correct |
13 |
Correct |
5 ms |
1052 KB |
Output is correct |
14 |
Correct |
5 ms |
1052 KB |
Output is correct |
15 |
Correct |
5 ms |
1072 KB |
Output is correct |
16 |
Correct |
6 ms |
1092 KB |
Output is correct |
17 |
Correct |
6 ms |
1240 KB |
Output is correct |
18 |
Correct |
5 ms |
1240 KB |
Output is correct |
19 |
Correct |
5 ms |
1240 KB |
Output is correct |
20 |
Correct |
5 ms |
1240 KB |
Output is correct |
21 |
Correct |
671 ms |
20112 KB |
Output is correct |
22 |
Correct |
578 ms |
21988 KB |
Output is correct |
23 |
Correct |
673 ms |
24052 KB |
Output is correct |
24 |
Correct |
384 ms |
25760 KB |
Output is correct |
25 |
Correct |
358 ms |
26496 KB |
Output is correct |
26 |
Correct |
341 ms |
26668 KB |
Output is correct |
27 |
Correct |
382 ms |
26668 KB |
Output is correct |
28 |
Correct |
382 ms |
26668 KB |
Output is correct |
29 |
Correct |
370 ms |
26668 KB |
Output is correct |
30 |
Correct |
359 ms |
26668 KB |
Output is correct |
31 |
Correct |
367 ms |
26668 KB |
Output is correct |
32 |
Correct |
378 ms |
26668 KB |
Output is correct |
33 |
Correct |
464 ms |
26668 KB |
Output is correct |
34 |
Correct |
477 ms |
26668 KB |
Output is correct |
35 |
Correct |
433 ms |
26668 KB |
Output is correct |
36 |
Correct |
687 ms |
26668 KB |
Output is correct |
37 |
Correct |
587 ms |
26668 KB |
Output is correct |
38 |
Correct |
568 ms |
26668 KB |
Output is correct |
39 |
Correct |
391 ms |
26668 KB |
Output is correct |
40 |
Correct |
333 ms |
26728 KB |
Output is correct |
41 |
Correct |
346 ms |
26728 KB |
Output is correct |
42 |
Correct |
369 ms |
26728 KB |
Output is correct |
43 |
Correct |
345 ms |
26728 KB |
Output is correct |
44 |
Correct |
359 ms |
26728 KB |
Output is correct |
45 |
Correct |
381 ms |
26728 KB |
Output is correct |
46 |
Correct |
490 ms |
26840 KB |
Output is correct |
47 |
Correct |
454 ms |
26840 KB |
Output is correct |
48 |
Correct |
482 ms |
26840 KB |
Output is correct |
49 |
Correct |
534 ms |
26840 KB |
Output is correct |
50 |
Correct |
516 ms |
26840 KB |
Output is correct |