QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216987 | #6331. Jewel Game | CharlieVinnie | WA | 14ms | 4292kb | C++17 | 2.3kb | 2023-10-16 10:44:35 | 2023-10-16 10:44:35 |
Judging History
answer
#include "bits/stdc++.h"
#ifdef DEBUG
#if __cplusplus >= 201700
#include "PrettyDebug.hpp"
#else
#define debug(a) cerr<<"(Line "<<__LINE__<<"): "<<#a<<" = "<<a<<'\n'
#endif
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll;
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
int n,m,A,B; cin>>n>>m>>A>>B; vector<vector<int>> to(n),fo(n); For(i,1,m) { int x,y; cin>>x>>y; to[x-1].push_back(y-1); fo[y-1].push_back(x-1); }
int K; cin>>K; vector<int> val(n); For(i,1,K) { int x,y; cin>>x>>y; val[x-1]=y; }
vector<vector<vector<int>>> f(1<<n,vector<vector<int>>(n,vector<int>(n,-1e9)));
For(i,0,n-1) For(j,0,n-1) f[0][i][j]=0;
For(s,1,(1<<n)-1){
auto& F=f[s]; vector<vector<int>> out(n,vector<int>(n));
For(u,0,n-1) For(v,0,n-1) for(int w:to[u]) if(val[w]&&((s>>w)&1)) F[u][v]=max(F[u][v],val[w]-f[s^1<<w][v][w]); else out[u][v]++;
priority_queue<tuple<int,int,int>> Q; For(u,0,n-1) For(v,0,n-1) Q.emplace(F[u][v],u,v);
queue<pair<int,int>> q; For(u,0,n-1) For(v,0,n-1) if(!out[u][v]) q.emplace(u,v);
while(q.size()||Q.size()){
while(q.size()){
auto [u,v]=q.front(); q.pop(); assert(!out[u][v]);
for(int w:fo[v]) if(out[w][u]) { Q.emplace(F[w][u]=max(F[w][u],-F[u][v]),w,u); if(!--out[w][u]) q.emplace(w,u); }
}
while(Q.size()){
auto [_,u,v]=Q.top(); Q.pop(); if(out[u][v]) {
if(F[u][v]>0) { out[u][v]=0,q.emplace(u,v); break; } else goto OUT;
}
}
}
OUT: For(u,0,n-1) For(v,0,n-1) if(out[u][v]) F[u][v]=0;
}
cout<<f[(1<<n)-1][A-1][B-1]<<'\n';
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE
// Started Coding On: October 16 Mon, 10 : 23 : 14
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
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: 3616kb
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: 0ms
memory: 3484kb
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: 14ms
memory: 4292kb
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'