QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97493 | #6331. Jewel Game | jeroenodb# | WA | 5ms | 9528kb | C++20 | 2.4kb | 2023-04-16 22:51:54 | 2023-04-16 22:51:57 |
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, oo = 2e9 + 20;
int dp[mxN][mxN][1<<10];
int escapes[mxN][mxN][1<<10];
int where[10];
int val[10];
bitset<1<<10> vis[mxN][mxN];
vi rev[mxN],adj[mxN];
struct el {
int a,b,msk;
int v;
bool operator<(const el& o) const {
if(msk!=o.msk) return msk>o.msk;
return v<o.v;
}
};
priority_queue<el> q;
void process(int a, int b, int msk, int v) {
// escapes[a][b][msk]--;
if(v>dp[a][b][msk]) {
dp[a][b][msk]=v;
// if(dp[a][b][msk]>=0)
q.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) {
process(i,j,0,0);
}
while(!q.empty()) {
auto e = q.top(); q.pop();
int& v = dp[e.a][e.b][e.msk];
if(vis[e.a][e.b][e.msk]) continue;
vis[e.a][e.b][e.msk]=1;
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];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5416kb
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: 0ms
memory: 5440kb
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: 2ms
memory: 5468kb
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: 5ms
memory: 9528kb
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:
-2000000020
result:
wrong answer 1st numbers differ - expected: '132484345', found: '-2000000020'