QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211851 | #6331. Jewel Game | sinsop90 | RE | 0ms | 0kb | C++14 | 1.6kb | 2023-10-12 21:47:29 | 2023-10-12 21:47:30 |
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;
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 >> m >> A >> B;
for(int i = 1, u, v;i <= m;i++) {
cin >> u >> v;
out[u].push_back(v), in[v].push_back(u);
}
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];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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