QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210497 | #6331. Jewel Game | ucup-team870 | WA | 1ms | 6080kb | C++14 | 3.1kb | 2023-10-11 15:20:03 | 2023-10-11 15:20:03 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N = 33;
vector<int> e[N], sta[N], b[N];
int pos[N], w[N], f[(1<<10)+2][33][33], id[N], du[N][N], vis[N][N];
P tmp[1025];
queue <P> q;
multiset<P> ksj;
int main() {
int n, m, A, B;
scanf("%d%d%d%d", &n, &m, &A, &B);
rep (i, 1, m) {
int u, v;
scanf("%d%d", &u, &v);
e[u].push_back(v);
b[v].push_back(u);
}
int k; scanf("%d", &k);
rep (i, 1, k) {
scanf("%d%d", &pos[i], &w[i]);
id[pos[i]] = i;
}
int mx = (1<<k) - 1;
rep (s, 1, mx) {
sta[__builtin_popcount(s)].push_back(s);
}
rep (s, 1, mx) {
rep(i, 1, n) {
rep (j, 1, n) {
f[s][i][j] = -1e9;
}
}
}
rep (_, 1, k) {
for (auto s: sta[_]) {
auto g = f[s];
rep (i, 1, n) {
rep (j, 1, n) {
int top = 0;
for (auto v: e[i]) {
int p = id[v];
if ((s>>p-1) & 1) {
int t = s ^ (1<<p-1);
g[i][j] = max(g[i][j], -f[t][j][v] + w[p]);
tmp[++top] = P(-f[t][j][v] + w[p], i * n + j - 1);
} else {
du[i][j]++;
}
}
if (du[i][j] == 0) {
vis[i][j] = 1;
q.push(P(i, j));
} else {
while (top) ksj.insert(tmp[top--]);
}
}
}
while (1) {
while (!q.empty()) {
auto [i, j] = q.front();
q.pop();
for (auto v: b[j]) { //previous: (v, i)
// if (vis[v][i]) continue;
du[v][i]--;
g[v][i] = max(g[v][i], -g[i][j]);
if (du[v][i] == 0) {
vis[v][i] = 1;
q.push(P(v, i));
} else {
// ksj.insert(P(-g[i][j], v*n + i - 1));
}
}
}
if (ksj.empty()) break;
auto [v, t] = *ksj.begin();
ksj.erase(ksj.begin());
int i = t/n, j = t%n+1;
// if (vis[i][j]) continue;
vis[i][j] = 1;
g[i][j] = v;
q.push(P(i, j));
break;
}
rep (i, 1, n) {
rep (j, 1, n) {
if (!vis[i][j]) g[i][j] = 0;
vis[i][j] = du[i][j] = 0;
}
}
}
}
cout << f[mx][A][B];
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6080kb
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:
12
result:
wrong answer 1st numbers differ - expected: '46', found: '12'