답안 #285900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285900 2020-08-29T17:55:23 Z YJU Candies (JOI18_candies) C++14
100 / 100
939 ms 27452 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=2e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,u[N],ans,vis[N];
multiset<pll,greater<pll> > ms;
set<ll> idx;

int main(){
	//ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP1(i,n)cin>>u[i],ms.insert(mp(u[i],i)),idx.insert(i);
	u[0]=u[n+1]=-INF;
	REP1(i,(n+1)/2){
		pll tmp=*ms.begin();ms.erase(ms.begin());
		ans+=tmp.X;
		cout<<ans<<"\n";
		if(i==(n+1)/2)break;
		ll l=(idx.lwb(tmp.Y)==idx.begin()?0:*prev(idx.lwb(tmp.Y)));
		ll r=(idx.lwb(tmp.Y+1)==idx.end()?0:*idx.lwb(tmp.Y+1));
		u[tmp.Y]=-tmp.X+u[l]+u[r];
		ms.erase(mp(u[l],l));ms.erase(mp(u[r],r));
		idx.erase(l);idx.erase(r);
		ms.insert(mp(u[tmp.Y],tmp.Y));
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 4 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 4 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 4 ms 640 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 4 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 4 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 4 ms 640 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 874 ms 27304 KB Output is correct
22 Correct 939 ms 27200 KB Output is correct
23 Correct 873 ms 27256 KB Output is correct
24 Correct 411 ms 27128 KB Output is correct
25 Correct 420 ms 27256 KB Output is correct
26 Correct 421 ms 27128 KB Output is correct
27 Correct 450 ms 27256 KB Output is correct
28 Correct 450 ms 27256 KB Output is correct
29 Correct 451 ms 27388 KB Output is correct
30 Correct 461 ms 27384 KB Output is correct
31 Correct 465 ms 27256 KB Output is correct
32 Correct 467 ms 27384 KB Output is correct
33 Correct 590 ms 27000 KB Output is correct
34 Correct 612 ms 27128 KB Output is correct
35 Correct 595 ms 27084 KB Output is correct
36 Correct 893 ms 27384 KB Output is correct
37 Correct 803 ms 27384 KB Output is correct
38 Correct 800 ms 27384 KB Output is correct
39 Correct 420 ms 27128 KB Output is correct
40 Correct 418 ms 27128 KB Output is correct
41 Correct 424 ms 27228 KB Output is correct
42 Correct 464 ms 27256 KB Output is correct
43 Correct 452 ms 27256 KB Output is correct
44 Correct 457 ms 27304 KB Output is correct
45 Correct 467 ms 27256 KB Output is correct
46 Correct 463 ms 27452 KB Output is correct
47 Correct 467 ms 27384 KB Output is correct
48 Correct 581 ms 26988 KB Output is correct
49 Correct 594 ms 27292 KB Output is correct
50 Correct 581 ms 27160 KB Output is correct