QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209126#6331. Jewel GamewullaaaWA 1ms3672kbC++141.7kb2023-10-10 10:27:282023-10-10 10:27:29

Judging History

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

  • [2023-10-10 10:27:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3672kb
  • [2023-10-10 10:27:28]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=35;
const ll INF=1e12;
int n,m,A,B,k;
int id[N],val[N],d[N][N];
ll dp[1<<10][N][N],tmp[N][N];
bool edge[N][N],vis[N][N];
vector<pii> e[N][N];
struct node{
	int fi,se; ll val;
	bool operator < (const node &other)const{
		return val<other.val;
	}
};
priority_queue<node> q;
void work(int s,int x,int y){
	if(vis[x][y]) return;
	vis[x][y]=true,dp[s][x][y]=tmp[x][y];
	for(auto t:e[x][y]){
		int a=t.fi,b=t.se;
		if(tmp[a][b]<-dp[s][x][y]) tmp[a][b]=-dp[s][x][y],q.push({a,b,tmp[a][b]});
		if(!(--d[a][b])) work(s,a,b);
	}
}
int main(){
	scanf("%d%d%d%d",&n,&m,&A,&B);
	for(int i=1,u,v;i<=m;++i) scanf("%d%d",&u,&v),edge[u][v]=true;
	scanf("%d",&k);
	for(int i=1;i<=n;++i) id[i]=k+1;
	for(int i=1,x,w;i<=k;++i) scanf("%d%d",&x,&w),id[x]=i,val[x]=w;
	for(int s=0;s<(1<<k);++s){
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) e[i][j].clear(),d[i][j]=vis[i][j]=0;
		for(int i=1;i<=n;++i) if(!(s>>(id[i]-1)&1))
			for(int j=1;j<=n;++j) if(!(s>>(id[j]-1)&1)){
				tmp[i][j]=-INF;
				for(int k=1;k<=n;++k) if(edge[i][k]){
					if(s>>(id[k]-1)&1) tmp[i][j]=max(tmp[i][j],val[k]-dp[s&(1<<(id[k]-1))][j][k]);
					else e[j][k].pb({i,j}),++d[i][j];
				}
			}
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(!d[i][j]) work(s,i,j);
		while(q.size()) q.pop();
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(!vis[i][j]) q.push({i,j,tmp[i][j]});
		while(q.size()){
			int x=q.top().fi,y=q.top().se; q.pop();
			if(tmp[x][y]<=0) break;
			work(s,x,y);
		}
	}
	printf("%lld",dp[(1<<k)-1][A][B]);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3672kb

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:

1000000000004

result:

wrong answer 1st numbers differ - expected: '46', found: '1000000000004'