Submission #44342

# Submission time Handle Problem Language Result Execution time Memory
44342 2018-03-31T12:51:31 Z zadrga Candies (JOI18_candies) C++14
100 / 100
1029 ms 39376 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll arr[maxn];
set<pair<ll, int> > s;
set<pair<int, ll> > ind;
vector<ll> ans;

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%lld", arr + i);
		s.insert(mp(-arr[i], i));
		ind.insert(mp(i, -arr[i]));
	}


	// ne smemo izbrati robnih, ker se število ohrani
	ind.insert(mp(0, INF));		
	ind.insert(mp(n + 1, INF));
	s.insert(mp(INF, 0));
	s.insert(mp(INF, n + 1));

	ll cur = 0;

	for(int k = 0; k < (n + 1) / 2; k++){
		vector<pair<ll, int> > v;

		auto it = s.begin();
		cur = cur + (-it -> fi);
		ans.pb(cur);

		auto it1 = ind.lower_bound(mp(it -> se, -INF));
		it1--;

		auto it2 = ind.lower_bound(mp(it -> se, -INF)); 
		it2++;

		v.pb(*it);
		v.pb(mp(it1 -> se, it1 -> fi));
		v.pb(mp(it2 -> se, it2 -> fi));
		
		int pos = it -> se;
		ll tren = it1 -> se + it2 -> se - it -> fi;

		for(auto i : v){
			s.erase(mp(i.fi, i.se));
			ind.erase(mp(i.se, i.fi));
		}

		s.insert(mp(tren, pos));
		ind.insert(mp(pos, tren));
	}

	for(ll i : ans)
		printf("%lld\n", i);
		
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
candies.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", arr + i);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 688 KB Output is correct
4 Correct 11 ms 784 KB Output is correct
5 Correct 5 ms 916 KB Output is correct
6 Correct 5 ms 992 KB Output is correct
7 Correct 5 ms 992 KB Output is correct
8 Correct 6 ms 992 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 5 ms 992 KB Output is correct
11 Correct 7 ms 992 KB Output is correct
12 Correct 5 ms 1048 KB Output is correct
13 Correct 5 ms 1048 KB Output is correct
14 Correct 4 ms 1048 KB Output is correct
15 Correct 5 ms 1048 KB Output is correct
16 Correct 5 ms 1124 KB Output is correct
17 Correct 5 ms 1124 KB Output is correct
18 Correct 6 ms 1124 KB Output is correct
19 Correct 5 ms 1124 KB Output is correct
20 Correct 4 ms 1124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 688 KB Output is correct
4 Correct 11 ms 784 KB Output is correct
5 Correct 5 ms 916 KB Output is correct
6 Correct 5 ms 992 KB Output is correct
7 Correct 5 ms 992 KB Output is correct
8 Correct 6 ms 992 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 5 ms 992 KB Output is correct
11 Correct 7 ms 992 KB Output is correct
12 Correct 5 ms 1048 KB Output is correct
13 Correct 5 ms 1048 KB Output is correct
14 Correct 4 ms 1048 KB Output is correct
15 Correct 5 ms 1048 KB Output is correct
16 Correct 5 ms 1124 KB Output is correct
17 Correct 5 ms 1124 KB Output is correct
18 Correct 6 ms 1124 KB Output is correct
19 Correct 5 ms 1124 KB Output is correct
20 Correct 4 ms 1124 KB Output is correct
21 Correct 1029 ms 31856 KB Output is correct
22 Correct 964 ms 33568 KB Output is correct
23 Correct 947 ms 35344 KB Output is correct
24 Correct 417 ms 37196 KB Output is correct
25 Correct 403 ms 38884 KB Output is correct
26 Correct 391 ms 39220 KB Output is correct
27 Correct 428 ms 39220 KB Output is correct
28 Correct 418 ms 39220 KB Output is correct
29 Correct 479 ms 39220 KB Output is correct
30 Correct 560 ms 39220 KB Output is correct
31 Correct 497 ms 39220 KB Output is correct
32 Correct 486 ms 39220 KB Output is correct
33 Correct 636 ms 39220 KB Output is correct
34 Correct 675 ms 39220 KB Output is correct
35 Correct 658 ms 39244 KB Output is correct
36 Correct 942 ms 39244 KB Output is correct
37 Correct 911 ms 39244 KB Output is correct
38 Correct 923 ms 39244 KB Output is correct
39 Correct 395 ms 39244 KB Output is correct
40 Correct 400 ms 39244 KB Output is correct
41 Correct 405 ms 39244 KB Output is correct
42 Correct 420 ms 39244 KB Output is correct
43 Correct 417 ms 39244 KB Output is correct
44 Correct 418 ms 39244 KB Output is correct
45 Correct 448 ms 39244 KB Output is correct
46 Correct 460 ms 39244 KB Output is correct
47 Correct 444 ms 39244 KB Output is correct
48 Correct 597 ms 39376 KB Output is correct
49 Correct 600 ms 39376 KB Output is correct
50 Correct 594 ms 39376 KB Output is correct