QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97502 | #6331. Jewel Game | jeroenodb | WA | 1157ms | 31548kb | C++20 | 2.6kb | 2023-04-16 23:27:53 | 2023-04-16 23:27: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 wish=0;
bool operator<(const el& o) const {
if(msk!=o.msk) return msk>o.msk;
if(wish!=o.wish) return wish>o.wish;
return v<o.v;
}
};
priority_queue<el> q,q2;
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) {
q2.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;
q.push({i,j,msk,0,1});
}
for(int i=0;i<n;++i) for(int j=0;j<n;++j) {
process(i,j,0,0);
}
while(!q.empty() or !q2.empty()) {
auto& myq = q2.empty() or (!q.empty() and q.top().msk<q2.top().msk)?q:q2;
auto e = myq.top(); myq.pop();
int& v = dp[e.a][e.b][e.msk];
if(vis[e.a][e.b][e.msk]) continue;
if(e.wish) {
if(e.v>v) {
v=e.v;
}
}
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: 3ms
memory: 5456kb
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: 4ms
memory: 7704kb
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: 7484kb
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: 0
Accepted
time: 9ms
memory: 9828kb
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:
132484345
result:
ok 1 number(s): "132484345"
Test #5:
score: 0
Accepted
time: 1157ms
memory: 31548kb
input:
30 900 1 2 2 25 8 21 22 16 26 29 12 24 1 8 7 14 22 27 27 20 5 24 21 21 21 10 30 28 5 16 12 3 16 1 21 2 24 23 24 14 9 7 9 18 20 22 6 1 30 3 11 6 2 17 18 13 28 20 5 15 26 16 9 14 30 23 4 23 4 2 9 5 21 29 1 30 12 14 16 27 28 22 15 7 23 10 13 16 1 15 22 9 13 12 30 18 10 5 25 28 3 17 30 30 7 17 11 24 12 ...
output:
40915541
result:
ok 1 number(s): "40915541"
Test #6:
score: 0
Accepted
time: 1105ms
memory: 31336kb
input:
30 900 1 1 16 16 26 15 20 25 9 28 27 1 25 18 12 6 7 26 14 15 28 21 18 19 12 3 26 29 28 24 8 8 22 9 18 3 9 2 26 9 29 21 13 28 21 24 18 2 30 8 1 25 19 26 4 19 2 25 14 27 14 12 2 23 23 15 16 5 9 29 10 27 29 16 16 20 5 8 3 28 12 12 30 7 16 29 30 17 3 11 21 26 18 14 14 6 26 4 21 29 3 6 11 15 22 4 14 18 1...
output:
38892888
result:
ok 1 number(s): "38892888"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5876kb
input:
9 58 5 4 4 6 8 9 5 3 6 5 7 1 5 9 6 3 2 1 4 8 2 9 3 4 1 2 8 5 5 2 1 3 2 3 9 5 4 3 3 1 5 4 9 1 6 7 2 8 7 3 2 5 8 3 2 7 5 8 4 7 9 2 4 5 5 7 3 7 6 8 1 4 9 4 9 8 7 9 1 1 4 4 3 6 1 8 6 6 5 5 9 9 5 1 1 6 2 4 3 2 5 6 3 3 2 6 7 4 6 2 3 9 6 9 8 8 9 7 2 1 28323506 7 18381394
output:
46704900
result:
ok 1 number(s): "46704900"
Test #8:
score: 0
Accepted
time: 1ms
memory: 7824kb
input:
8 11 4 4 4 6 7 6 8 2 5 8 3 4 2 3 8 6 5 1 6 6 1 8 8 4 4 2 75547123 5 9278878 7 13909469 8 57425260
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 3ms
memory: 7568kb
input:
4 10 1 2 2 3 1 3 4 4 1 4 3 3 4 3 1 2 3 1 2 4 1 1 2 3 35669800 4 36664186
output:
994386
result:
ok 1 number(s): "994386"
Test #10:
score: 0
Accepted
time: 16ms
memory: 11060kb
input:
17 125 15 14 12 5 13 11 13 12 9 13 16 2 13 3 1 14 16 14 13 10 3 2 17 14 14 12 8 11 10 1 9 8 14 2 13 6 3 3 7 1 11 12 16 17 10 4 15 10 12 11 10 10 4 9 14 16 9 3 4 8 15 5 2 12 7 11 14 1 10 3 4 11 4 4 8 12 8 7 9 16 15 13 17 9 1 10 8 5 13 4 13 16 15 15 9 10 17 4 10 17 2 16 13 1 15 9 5 7 14 11 10 9 5 5 9 ...
output:
-33927098
result:
ok 1 number(s): "-33927098"
Test #11:
score: 0
Accepted
time: 4ms
memory: 6020kb
input:
11 18 8 7 5 11 9 3 1 8 6 11 11 5 5 9 1 9 2 5 10 2 4 10 7 1 6 2 10 8 3 9 8 6 3 7 7 11 2 10 5 2 22754552 5 84549882 6 19922948 9 13449629 11 18334746
output:
-73656757
result:
ok 1 number(s): "-73656757"
Test #12:
score: 0
Accepted
time: 3ms
memory: 5344kb
input:
3 8 2 3 1 3 3 2 1 2 3 3 2 1 2 3 3 1 2 2 1 1 53102229
output:
53102229
result:
ok 1 number(s): "53102229"
Test #13:
score: 0
Accepted
time: 2ms
memory: 5356kb
input:
3 6 1 1 1 3 2 3 3 1 2 2 1 2 2 1 1 3 88674071
output:
88674071
result:
ok 1 number(s): "88674071"
Test #14:
score: 0
Accepted
time: 1ms
memory: 9832kb
input:
10 22 3 3 5 6 2 9 1 4 6 4 7 9 3 4 4 3 4 2 6 3 10 8 8 1 8 2 9 4 5 10 4 10 7 3 7 6 10 9 1 1 1 10 10 5 2 3 4 1 12017417 2 33560186 9 68408625 10 44302781
output:
91168637
result:
ok 1 number(s): "91168637"
Test #15:
score: 0
Accepted
time: 3ms
memory: 9884kb
input:
11 76 11 6 11 9 4 8 4 2 11 4 7 7 9 8 5 2 7 3 1 4 8 8 6 1 2 7 7 4 9 6 10 6 7 9 3 5 1 8 2 11 1 6 4 1 10 2 4 11 4 4 2 8 8 9 11 10 8 4 8 5 3 4 4 5 11 5 11 8 10 3 8 3 7 6 4 9 1 7 1 10 7 5 10 4 5 6 6 10 5 5 7 11 8 11 2 2 6 9 1 5 2 3 8 1 3 10 6 3 9 10 5 8 7 10 1 11 4 3 2 9 5 10 9 5 3 1 5 7 6 5 9 3 5 11 3 6...
output:
18844044
result:
ok 1 number(s): "18844044"
Test #16:
score: 0
Accepted
time: 2ms
memory: 5668kb
input:
5 8 2 5 5 4 4 1 3 5 1 5 1 2 2 5 3 3 3 1 3 1 89861734 3 78638917 4 76333187
output:
-166194921
result:
ok 1 number(s): "-166194921"
Test #17:
score: -100
Wrong Answer
time: 316ms
memory: 31364kb
input:
24 34 21 10 17 17 19 21 22 24 8 4 10 11 7 11 18 20 9 15 17 7 2 8 5 4 13 6 11 5 21 11 12 16 7 23 3 13 16 7 1 3 23 18 6 2 20 24 19 20 14 13 15 9 2 14 4 24 24 1 1 4 5 12 11 22 14 23 2 20 8 15 10 4 32206739 5 86258057 6 28124909 8 30711780 17 1439605 18 98665106 19 35462765 20 42495740 22 94507837 23 65...
output:
-63598465
result:
wrong answer 1st numbers differ - expected: '107651072', found: '-63598465'