QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#310743#6406. Stage ClearPlentyOfPenaltyWA 554ms401700kbC++202.1kb2024-01-21 17:21:372024-01-21 17:21:38

Judging History

This is the latest submission verdict.

  • [2024-08-15 21:05:17]
  • hack成功,自动添加数据
  • (/hack/778)
  • [2024-01-21 17:21:38]
  • Judged
  • Verdict: WA
  • Time: 554ms
  • Memory: 401700kb
  • [2024-01-21 17:21:37]
  • 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]);
}
void dfs(int x){
	if(x>n){
		p.clr();
		na[1]=nb[1]=0,fa[1]=1;
		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();
			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){
		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5656kb

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: 0
Accepted
time: 2ms
memory: 6252kb

input:

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

output:

1665396301509143

result:

ok 1 number(s): "1665396301509143"

Test #3:

score: 0
Accepted
time: 7ms
memory: 13252kb

input:

18 17
636830992776530 847574431876821
330869946457865 78274534165482
450581372553540 11565219334965
8736347226844 17186323694285
870805093198860 559070167736042
674369178493171 930151818400874
641605209598997 222521062460239
450936030349531 469197172169023
831295459816974 626096008793091
53095460351...

output:

2375957544280218

result:

ok 1 number(s): "2375957544280218"

Test #4:

score: 0
Accepted
time: 30ms
memory: 30324kb

input:

20 19
539893468691183 767805205447882
240338186903141 960937349402327
942645580569365 896509929612645
542601575005817 191461109090531
540992546866047 765080044816119
904535155855114 858111921213175
452499200048240 115895143306864
983856946412026 838504718536099
586421298181479 265212699386882
677124...

output:

800919806038419

result:

ok 1 number(s): "800919806038419"

Test #5:

score: 0
Accepted
time: 554ms
memory: 401700kb

input:

24 23
114281007218527 308690671179962
145951034437731 718976086594208
709172151907814 926071954787084
224496444610281 498657753059525
874422017133378 857676356343078
532175866197017 818525693672607
303837639402605 374469705563954
512244364294540 952911486867703
748959419417502 249992707230361
512696...

output:

114281007218527

result:

ok 1 number(s): "114281007218527"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

36 35
389328367777319 678636570542258
32216944647452 612585362150577
891592845704885 596030605892036
688825276167602 461516360471825
916552899998310 106733202183953
400050408958777 670724326933521
995792861502757 894514508573875
14511185222713 612305257166443
175168368096281 508263855969282
85578802...

output:

171942144116875

result:

ok 1 number(s): "171942144116875"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

36 35
759037289890767 849577210686635
16379509883489 441829377955433
589378488455351 990818352083122
871208015900506 727359003875494
207852561142533 28766987248469
81321183353129 892618157632070
198487099788393 519364502513651
83942803274015 988821788304459
868185445880277 269956013388079
3834515054...

output:

759037289890767

result:

ok 1 number(s): "759037289890767"

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3676kb

input:

36 35
100792831728257 823656493168793
866936535786311 187861146327778
132998929717538 605906559206892
3319598846477 393401056223733
964444786730964 932398059281618
925176496607384 148825907337833
985037559482190 646827297289525
469876125353024 641923164294854
453796287874442 291205025001534
72806942...

output:

1195260543222396

result:

wrong answer 1st numbers differ - expected: '1397699717661157', found: '1195260543222396'