답안 #654963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654963 2022-11-02T08:56:04 Z onlk97 Candies (JOI18_candies) C++14
0 / 100
2 ms 484 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	long long a[n+2];
	a[0]=a[n+1]=-1e18;
	for (int i=1; i<=n; i++) cin>>a[i];
	long long l[n+1],r[n+1];
	for (int i=1; i<=n; i++){
		l[i]=i-1;
		r[i]=i+1;
	}
	l[0]=0; r[n+1]=n+1;
	bool used[n+2];
	for (int i=0; i<=n+1; i++) used[i]=0;
	set <pair <long long,int>,greater <pair <long long,int> > > s;
	for (int i=1; i<=n; i++) s.insert(make_pair(a[i],i));
	long long ans=0;
	for (int iters=1; iters<=(n+1)/2; iters++){
		die:;
		pair <long long,int> tp=*s.begin(); s.erase(s.begin());
		if (used[tp.second]) goto die;
		ans+=tp.first;
		cout<<ans<<'\n';
		int ll=l[tp.second],rr=r[tp.second];
		a[tp.second]=a[ll]+a[rr]-a[tp.second];
		l[tp.second]=l[ll];
		r[tp.second]=r[rr];
		used[ll]=1;
		used[rr]=1;
		r[l[tp.second]]=tp.second;
		l[r[tp.second]]=tp.second;
		if (ll>=1&&rr<=n) s.insert(make_pair(a[tp.second],tp.second));
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Incorrect 1 ms 468 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Incorrect 1 ms 468 KB Output isn't correct
19 Halted 0 ms 0 KB -