답안 #128781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128781 2019-07-11T09:26:56 Z jangwonyoung Sparklers (JOI17_sparklers) C++14
50 / 100
2000 ms 7292 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n,k;
ll t;
ll x[100001];
bool got[100001];
struct mob{
	ll fi,se;
};
mob operator+(mob x,mob y){
	ll a=max(x.fi,x.fi-x.se+y.fi);
	ll b=x.se-x.fi+y.se-y.fi+a;
	return (mob){a,b};
}
bool operator<(mob x,mob y){
	bool sx=x.fi<x.se,sy=y.fi<y.se;
	if(sx!=sy) return sx>sy;
	if(x.fi<x.se) return x.fi<y.fi;
	return x.se>y.se;
}
priority_queue<pair<mob,int>,vector<pair<mob,int> >,greater<pair<mob,int> > >cave;
int cp[100001],cs[100001];
bool vis[100001];
mob val[100001];
bool solve(ll s){
	ll blood=s;
	for(int i=1; i<=n ;i++) cp[i]=cs[i]=i;
	for(int i=1; i<=n ;i++) vis[i]=false;
	while(!cave.empty()) cave.pop();
	for(int i=1; i<k ;i++){
		val[i]={x[i+1]-x[i],s};
		cave.push({val[i],i});
	}
	for(int i=n; i>k ;i--){
		val[i]={x[i]-x[i-1],s};
		cave.push({val[i],i});
	}
	while(!cave.empty()){
		auto cur=cave.top();cave.pop();
		if(vis[cur.se] || val[cur.se].fi!=cur.fi.fi || val[cur.se].se!=cur.fi.se) continue;
		vis[cur.se]=true;
		int par=cur.se+(cur.se<k)-(cur.se>k);
		cp[cs[cur.se]]=cp[par];
		cs[cp[par]]=cs[cur.se];
		if(cp[par]==k){//execute
			blood-=cur.fi.fi;
			if(blood<0) return false;
			blood+=cur.fi.se;
		}
		else{//merge
			val[cp[par]]=val[cp[par]]+val[cur.se];
			cave.push({val[cp[par]],cp[par]});
		}
	}	
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k >> t;
	for(int i=1; i<=n ;i++){
		cin >> x[i];
	}
	ll l=0,r=1e9/t+1;
	while(l!=r){
		ll mid=(l+r)/2;
		if(solve(mid*t*2)) r=mid;
		else l=mid+1;
	}
	cout << l << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 424 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 424 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 7 ms 400 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 9 ms 500 KB Output is correct
25 Correct 13 ms 504 KB Output is correct
26 Correct 11 ms 504 KB Output is correct
27 Correct 12 ms 504 KB Output is correct
28 Correct 11 ms 504 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 11 ms 504 KB Output is correct
31 Correct 11 ms 504 KB Output is correct
32 Correct 12 ms 504 KB Output is correct
33 Correct 11 ms 504 KB Output is correct
34 Correct 12 ms 504 KB Output is correct
35 Correct 11 ms 504 KB Output is correct
36 Correct 11 ms 508 KB Output is correct
37 Correct 11 ms 376 KB Output is correct
38 Correct 11 ms 504 KB Output is correct
39 Correct 11 ms 504 KB Output is correct
40 Correct 7 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 424 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 7 ms 400 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 9 ms 500 KB Output is correct
25 Correct 13 ms 504 KB Output is correct
26 Correct 11 ms 504 KB Output is correct
27 Correct 12 ms 504 KB Output is correct
28 Correct 11 ms 504 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 11 ms 504 KB Output is correct
31 Correct 11 ms 504 KB Output is correct
32 Correct 12 ms 504 KB Output is correct
33 Correct 11 ms 504 KB Output is correct
34 Correct 12 ms 504 KB Output is correct
35 Correct 11 ms 504 KB Output is correct
36 Correct 11 ms 508 KB Output is correct
37 Correct 11 ms 376 KB Output is correct
38 Correct 11 ms 504 KB Output is correct
39 Correct 11 ms 504 KB Output is correct
40 Correct 7 ms 504 KB Output is correct
41 Correct 534 ms 4972 KB Output is correct
42 Correct 28 ms 632 KB Output is correct
43 Correct 162 ms 2036 KB Output is correct
44 Correct 1842 ms 7272 KB Output is correct
45 Correct 1806 ms 7148 KB Output is correct
46 Correct 1791 ms 7144 KB Output is correct
47 Correct 1868 ms 7272 KB Output is correct
48 Correct 1903 ms 7280 KB Output is correct
49 Correct 1871 ms 7272 KB Output is correct
50 Correct 1827 ms 7144 KB Output is correct
51 Correct 1828 ms 7276 KB Output is correct
52 Correct 1866 ms 7272 KB Output is correct
53 Correct 1798 ms 7272 KB Output is correct
54 Correct 1858 ms 7144 KB Output is correct
55 Correct 1730 ms 7272 KB Output is correct
56 Correct 1798 ms 7144 KB Output is correct
57 Correct 1769 ms 7144 KB Output is correct
58 Correct 1749 ms 7144 KB Output is correct
59 Correct 803 ms 6504 KB Output is correct
60 Correct 1893 ms 7172 KB Output is correct
61 Correct 1805 ms 7148 KB Output is correct
62 Correct 1715 ms 7144 KB Output is correct
63 Correct 1792 ms 7292 KB Output is correct
64 Correct 1770 ms 7276 KB Output is correct
65 Correct 1816 ms 7272 KB Output is correct
66 Correct 1896 ms 7144 KB Output is correct
67 Correct 1819 ms 7256 KB Output is correct
68 Correct 1799 ms 7208 KB Output is correct
69 Execution timed out 2035 ms 7144 KB Time limit exceeded