QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#310769#6406. Stage ClearPlentyOfPenaltyRE 0ms3576kbC++202.2kb2024-01-21 17:34:172024-01-21 17:34:17

Judging History

This is the latest submission verdict.

  • [2024-08-15 21:05:17]
  • hack成功,自动添加数据
  • (/hack/778)
  • [2024-01-21 17:34:17]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3576kb
  • [2024-01-21 17:34:17]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=36,C=25;
const ll INF=1e18;
struct node{
	ll a,b;
	int id;
	bool operator<(const node&y)const{
		if((b-a>0)!=(y.b-y.a>0))return y.b-y.a>0;
		return b-a>0?a>y.a:b<y.b;
	}
	bool operator==(const node&y)const{
		return a==y.a&&b==y.b&&id==y.id;
	}
}t;
struct PQ{
	priority_queue<node>pq,del;
	void push(node x){pq.push(x);}
	void erase(node x){del.push(x);}
	void pop(){
		while(!del.empty()&&pq.top()==del.top())pq.pop(),del.pop();
		pq.pop();
	}
	node top(){
		while(!del.empty()&&pq.top()==del.top())pq.pop(),del.pop();
		return pq.top();
	}
	void clr(){
		while(!pq.empty())pq.pop();
		while(!del.empty())del.pop();
	}
	int size(){return pq.size()-del.size();}
}p;
int n,m,u,v,nf[N+10],fa[N+10],tp;
ll a[N+10],b[N+10],na[N+10],nb[N+10],mx,dt,ans=INF;
ll lb[(1<<C)+10],ss[(1<<C)+10],dp[(1<<C)+10],to;
vector<int>f[N+10];
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
int vis[N+10],TIM;
void dfs(int x){
	if(x>n){
		p.clr();
		na[1]=nb[1]=0,fa[1]=1;
		++TIM;
		for(int i=2;i<=n;++i)fa[i]=i,p.push((node){a[i],b[i],i}),na[i]=a[i],nb[i]=b[i];
		while(p.size()>1){
			t=p.top(),p.pop();
			assert(vis[t.id]!=TIM),vis[t.id]=TIM;
			//t.id=getf(t.id);
			tp=getf(nf[t.id]);
			if(tp!=1)p.erase((node){na[tp],nb[tp],tp});
			mx=max(na[tp],na[tp]-nb[tp]+t.a);
			nb[tp]=nb[tp]+t.b-na[tp]-t.a+mx,na[tp]=mx;
			fa[t.id]=tp;
			if(tp!=1)p.push((node){na[tp],nb[tp],tp});
		}
		ans=min(ans,na[1]);
		return;
	}
	for(int i:f[x])nf[x]=i,dfs(x+1);
}
int main(){
	cin.sync_with_stdio(0),cin.tie(0);
	cin>>n>>m;
	for(int i=2;i<=n;++i)cin>>a[i]>>b[i];
	//if(n>C)
	if(1){
		for(int i=1;i<=m;++i)cin>>u>>v,f[v].push_back(u);
		dfs(2);
		cout<<ans<<"\n";
	}else{
		for(int i=1;i<=m;++i)cin>>u>>v,fa[v]|=(1<<u-1);
		for(int i=1;i<(1<<n);++i)lb[i]=((i&1)?0:lb[i>>1]+1),ss[i]=ss[i-(1<<lb[i])]-a[lb[i]+1]+b[lb[i]+1];
		for(int i=2;i<(1<<n);++i)dp[i]=INF;
		for(int i=1;i<(1<<n);i+=2){
			for(int j=2;j<=n;++j)if(!((i>>j-1)&1)&&(i&fa[j])){
				to=i+(1<<j-1);
				dp[to]=min(dp[to],max(dp[i],a[j]-ss[i]));
			}
		}
		cout<<dp[(1<<n)-1]<<"\n";
	}
	return 0;
}
/*
4 4
4 2
5 3
2 6
1 2
1 3
2 4
3 4
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

4 4
4 2
5 3
2 6
1 2
1 3
2 4
3 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: -100
Runtime Error

input:

15 14
254040392438309 117083115436273
500005748229691 557255157630172
821034233718230 865199673774998
659892147898798 987564141425694
81172575487567 811635577877255
751768357864605 341103322647288
454926350150218 140191090713900
921608121471585 659295670987251
223751724062143 505619245326640
8907765...

output:


result: