QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642245#6331. Jewel GamelyxTL 1ms10316kbC++142.0kb2024-10-15 12:19:152024-10-15 12:19:19

Judging History

你现在查看的是最新测评结果

  • [2024-10-15 12:19:19]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:10316kb
  • [2024-10-15 12:19:15]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define ls (g<<1)
#define rs (g<<1|1)
#define md (l+r>>1)
#define Ls l,md,ls
#define Rs md+1,r,rs
#define ll long long
#define rll register ll
#define ull unsigned ll
#define D double
#define rd register D
#define eps 1e-10
#define ri register int
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define cr(x) memset(x,0,sizeof(x))
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
using namespace std;
const ll inf=1e18;
const int N=35,M=(1<<10)+5;
int n,m,A,B,pos[N],bz[N][N][M][2];
int k,w,pd[N],v[N];ll f[N][N][M][2];
vector<int>G[N],T[N];
inline void air(){}
inline ll dfs(ri x,ri y,ri s,ri o,ri dep){
	if(s==w-1)f[x][y][s][o]=0;
	if(f[x][y][s][o]!=-inf)return f[x][y][s][o];
	if(bz[x][y][s][o])return -inf;
	bz[x][y][s][o]=1;
	rll mx=-inf,mn=inf;
	if(x==2&&y==4&&s==14&&o==1)
	air();
	if(x==3&&y==5&&s==4&&o)
	air();
	if(x==1&&y==3&&s==5&&o&&dep==4)
	air();
	if(dep==2)
	air();
	if(!o){
		for(auto z:G[x]){
			if(z==2)
			air();
			if(pos[z]>=0&&!(s>>pos[z]&1))
				mx=max(mx,dfs(z,y,s|1<<pos[z],1,dep+1)+v[pos[z]]);
			else mx=max(mx,dfs(z,y,s,1,dep+1));
		}
		f[x][y][s][o]=mx;
	}
	else{
		for(auto z:G[y]){
			if(pos[z]>=0&&!(s>>pos[z]&1))
				mn=min(mn,dfs(x,z,s|1<<pos[z],0,dep+1)-v[pos[z]]);
			else mn=min(mn,dfs(x,z,s,0,dep+1));
		}
		f[x][y][s][o]=mn;
	}
	bz[x][y][s][o]=0;
	return f[x][y][s][o];
}
inline void fnd(ri x){
	pd[x]=1;
	for(auto y:T[x])if(!pd[y])fnd(y);
}
int main(){
	scanf("%d%d%d%d",&n,&m,&A,&B);
	fo(i,1,m){
		ri x,y;scanf("%d%d",&x,&y);
		G[x].pb(y);
		T[x].pb(y);T[y].pb(x);
	}
	fnd(A);fnd(B);
	scanf("%d",&k);
	ri tmp=k;k=0;
	fo(i,1,n)pos[i]=-1;
	fo(i,1,tmp){
		ri x;
		scanf("%d%d",&x,&v[k++]);
		if(!pd[x]){--k;continue;}
		pos[x]=i-1;
	}
	w=1<<k;
	fo(i,1,n)fo(j,1,n)fu(x,0,w)fo(y,0,1)f[i][j][x][y]=-inf;
	printf("%lld",dfs(A,B,0,0,1));
}

詳細信息

Test #1:

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

input:

5 16 1 1
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 2
3 4
3 5
4 2
4 3
4 5
5 2
5 3
5 4
4
2 4
3 84
4 38
5 96

output:

46

result:

ok 1 number(s): "46"

Test #2:

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

input:

8 16 8 4
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
1 5
2 6
3 7
4 8
5 1
6 2
7 3
8 4
6
1 29
2 34
3 41
5 7
6 26
7 94

output:

-23

result:

ok 1 number(s): "-23"

Test #3:

score: 0
Accepted
time: 1ms
memory: 10028kb

input:

5 5 2 1
1 1
2 3
3 4
4 5
5 2
2
4 1000000
5 100000

output:

1100000

result:

ok 1 number(s): "1100000"

Test #4:

score: -100
Time Limit Exceeded

input:

10 20 1 2
1 4
1 7
2 2
2 4
3 6
3 3
4 8
4 7
5 7
5 1
6 9
6 2
7 9
7 3
8 8
8 6
9 7
9 8
10 10
10 2
8
3 92067840
4 2874502
5 36253165
6 70758738
7 4768969
8 16029185
9 16207515
10 44912151

output:


result: