# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
101113 |
2019-03-16T17:04:00 Z |
gs14004 |
Candies (JOI18_candies) |
C++17 |
|
942 ms |
29848 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
typedef long long lint;
typedef pair<lint, int> pi;
const int mod = 1e9 + 7;
const lint inf = 1e15;
int n, a[MAXN];
struct node{
int st, ed;
lint cost;
bool operator<(const node &n)const{
return pi(cost, st) < pi(n.cost, n.st);
}
};
int main(){
scanf("%d",&n);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
}
auto cmp = [&](node s, node e){
return s.st < e.st;
};
set<node> pq;
set<node, decltype(cmp)> s(cmp);
auto InsertNode = [&](int st, int ed, lint x){
s.insert({st, ed, x});
pq.insert({st, ed, x});
};
InsertNode(0, 0, -inf);
for(int i=1; i<=n; i++){
InsertNode(i, i, a[i]);
}
InsertNode(n+1, n+1, -inf);
lint ans = 0;
for(int i=1; i<=(n+1)/2; i++){
auto nd = *--pq.end();
pq.erase(nd);
s.erase(nd);
ans += nd.cost;
printf("%lld\n", ans);
nd.cost *= -1;
int pst = nd.st, ped = nd.ed;
auto it = --s.lower_bound({pst, -1, -1});
nd.st = it->st;
nd.cost += it->cost;
pq.erase(*it);
s.erase(it);
it = s.lower_bound({ped + 1, -1, -1});
nd.ed = it->ed;
nd.cost += it->cost;
pq.erase(*it);
s.erase(it);
InsertNode(nd.st, nd.ed, nd.cost);
}
}
Compilation message
candies.cpp: In function 'int main()':
candies.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
candies.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
612 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
612 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
4 ms |
640 KB |
Output is correct |
21 |
Correct |
855 ms |
29660 KB |
Output is correct |
22 |
Correct |
942 ms |
29804 KB |
Output is correct |
23 |
Correct |
862 ms |
29712 KB |
Output is correct |
24 |
Correct |
334 ms |
29432 KB |
Output is correct |
25 |
Correct |
341 ms |
29432 KB |
Output is correct |
26 |
Correct |
380 ms |
29444 KB |
Output is correct |
27 |
Correct |
400 ms |
29660 KB |
Output is correct |
28 |
Correct |
359 ms |
29676 KB |
Output is correct |
29 |
Correct |
329 ms |
29688 KB |
Output is correct |
30 |
Correct |
356 ms |
29848 KB |
Output is correct |
31 |
Correct |
340 ms |
29560 KB |
Output is correct |
32 |
Correct |
398 ms |
29688 KB |
Output is correct |
33 |
Correct |
584 ms |
29392 KB |
Output is correct |
34 |
Correct |
622 ms |
29560 KB |
Output is correct |
35 |
Correct |
600 ms |
29488 KB |
Output is correct |
36 |
Correct |
903 ms |
29568 KB |
Output is correct |
37 |
Correct |
824 ms |
29784 KB |
Output is correct |
38 |
Correct |
925 ms |
29736 KB |
Output is correct |
39 |
Correct |
388 ms |
29432 KB |
Output is correct |
40 |
Correct |
381 ms |
29432 KB |
Output is correct |
41 |
Correct |
369 ms |
29356 KB |
Output is correct |
42 |
Correct |
335 ms |
29764 KB |
Output is correct |
43 |
Correct |
345 ms |
29532 KB |
Output is correct |
44 |
Correct |
357 ms |
29572 KB |
Output is correct |
45 |
Correct |
375 ms |
29692 KB |
Output is correct |
46 |
Correct |
380 ms |
29556 KB |
Output is correct |
47 |
Correct |
372 ms |
29560 KB |
Output is correct |
48 |
Correct |
585 ms |
29640 KB |
Output is correct |
49 |
Correct |
524 ms |
29420 KB |
Output is correct |
50 |
Correct |
544 ms |
29304 KB |
Output is correct |