QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#97497 | #6331. Jewel Game | jeroenodb# | WA | 3ms | 6660kb | C++20 | 2.9kb | 2023-04-16 23:09:26 | 2023-04-16 23:09:30 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 30;
const ll oo = 1e16 + 10;
ll dp[mxN][mxN][1<<10];
int where[10];
ll val[10];
bitset<1<<10> vis[mxN][mxN];
vi rev[mxN],adj[mxN];
struct el {
int a,b,msk;
ll v;
bool operator<(const el& o) const {
if(msk!=o.msk) return msk>o.msk;
return v<o.v;
}
};
queue<el> q[1<<10];
void process(int a, int b, int msk, ll v) {
// escapes[a][b][msk]--;
if(v>dp[a][b][msk]) {
dp[a][b][msk]=v;
// if(dp[a][b][msk]>=0)
q[msk].push({a,b,msk,v});
}
// if(escapes[a][b][msk]==0) {
// if(dp[a][b][msk]<0) {
// q.push({a,b,msk,dp[a][b][msk]});
// }
// }
}
int main() {
int n,m,a,b; cin >> n >> m >> a >> b;
--a,--b;
while(m--) {
int u,v; cin >> u >> v;
--u,--v;
rev[v].push_back(u);
adj[u].push_back(v);
}
int k; cin >> k;
for(int i=0;i<k;++i) {
cin >> where[i]; --where[i];
cin >> val[i];
}
for(int i=0;i<n;++i) for(int j=0;j<n;++j) for(int msk=0;msk<1<<k;++msk) {
// escapes[i][j][msk] = adj[i].size();
dp[i][j][msk]=-oo;
// if(msk) q.push({i,j,msk,0,1});
// if(msk==0) escapes[i][j][msk]=1;
}
for(int i=0;i<n;++i) for(int j=0;j<n;++j) {
vector<bool> vis(n);
auto dfs = [&](auto&& self, int at) -> void {
vis[at]=1;
for(int to : adj[at]) if(!vis[to]) {
self(self,to);
}
};
dfs(dfs,i);
dfs(dfs,j);
for(int msk=0;msk<(1<<k);++msk) {
bool good=0;
for(int o=0;o<k;++o) if((1<<o & msk) and vis[where[o]]) {
good=1;
}
if(!good) process(i,j,msk,0);
}
}
for(int mymsk=0;mymsk<1<<k;++mymsk) {
auto& myq = q[mymsk];
while(!myq.empty()) {
auto e = myq.front(); myq.pop();
int v = dp[e.a][e.b][e.msk];
for(auto from : rev[e.b]) {
process(from,e.a,e.msk, -v);
for(int j=0;j<k;++j) if(where[j]==e.b and (e.msk & 1<<j)==0) {
process(from,e.a,e.msk|(1<<j),-v + val[j]);
}
}
}
}
cout << dp[a][b][(1<<k)-1];
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4180kb
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: 3ms
memory: 6256kb
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: 3ms
memory: 6116kb
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
Wrong Answer
time: 2ms
memory: 6660kb
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:
164899375
result:
wrong answer 1st numbers differ - expected: '132484345', found: '164899375'