QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211854#6331. Jewel Gamesinsop90WA 1ms5736kbC++141.6kb2023-10-12 21:48:262023-10-12 21:48:27

Judging History

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

  • [2023-10-12 21:48:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5736kb
  • [2023-10-12 21:48:26]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 35, INF = 1e18;
int f[1035][maxn][maxn][2], las[maxn][maxn][2], n, m, A, B, ed;
vector<int> in[maxn], out[maxn];
struct ASK {
	int x, y;
}Q[maxn];
void gett(int S) {
	for(int u = 1;u <= n;u++) for(int v = 1;v <= n;v++) f[S][u][v][0] = f[S][u][v][1] = -INF;
	for(int i = 1;i <= m;i++) {
		if(!(S >> (i - 1) & 1)) continue;
		for(int v = 1;v <= n;v++) {
			for(int u : in[Q[i].x]) {
				if(f[S ^ (1 << i - 1)][Q[i].x][v][1] != -INF) f[S][u][v][0] = max(f[S][u][v][0], Q[i].y - f[S ^ (1 << i - 1)][Q[i].x][v][1]);
				if(f[S ^ (1 << i - 1)][u][Q[i].x][0] != -INF) f[S][v][u][1] = max(f[S][v][u][1], Q[i].y - f[S ^ (1 << i - 1)][u][Q[i].x][0]);
			}
		} 
	}
	while(1) {
		for(int u = 1;u <= n;u++) for(int v = 1;v <= n;v++) las[u][v][0] = f[S][u][v][0], las[u][v][1] = f[S][u][v][1];
		for(int u = 1;u <= n;u++) {
			for(int v = 1;v <= n;v++) {
				for(int x : out[u]) if(f[S][x][v][1] != -INF) f[S][u][v][0] = max(f[S][u][v][0], -f[S][x][v][1]);
				for(int x : out[v]) if(f[S][u][x][0] != -INF) f[S][u][v][1] = max(f[S][u][v][1], -f[S][u][x][0]);
			}
		}
		int flag = 0;
		for(int u = 1;u <= n;u++) for(int v = 1;v <= n;v++) for(int op = 0;op <= 1;op ++) if(las[u][v][op] != f[S][u][v][op]) flag = 1;
		if(!flag) break;
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> ed >> A >> B;
	for(int i = 1, u, v;i <= ed;i++) {
		cin >> u >> v;
		out[u].push_back(v), in[v].push_back(u);
	}
	cin >> m;
	for(int i = 1;i <= m;i++) cin >> Q[i].x >> Q[i].y;
	for(int i = 1;i < (1 << m);i++) gett(i);
	cout << f[(1 << m) - 1][A][B][0];
}

详细

Test #1:

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

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: -100
Wrong Answer
time: 1ms
memory: 5736kb

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:

-105

result:

wrong answer 1st numbers differ - expected: '-23', found: '-105'