Submission #128780

# Submission time Handle Problem Language Result Execution time Memory
128780 2019-07-11T09:26:41 Z jangwonyoung Sparklers (JOI17_sparklers) C++14
Compilation error
0 ms 0 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(!pq.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;
}

Compilation message

sparklers.cpp: In function 'bool solve(ll)':
sparklers.cpp:41:9: error: 'pq' was not declared in this scope
  while(!pq.empty()){
         ^~