QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97571 | #6331. Jewel Game | tricyzhkx | WA | 4ms | 5816kb | C++14 | 2.3kb | 2023-04-17 10:31:24 | 2023-04-17 10:31:24 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int INF=2e9;
typedef pair<int,int> pii;
int w[40],msk[40],du[40][40],f[1100][40][40];
bool good[40][40],vis[40][40];
vector<int> G[40];
vector<pii> G2[40][40];
struct node
{
int u,v,w;
node(int _u=0,int _v=0,int _w=0):u(_u),v(_v),w(_w){}
bool operator<(const node &a)const{return w<a.w;}
};
queue<pii> que;
priority_queue<node> pque;
template<typename T>
void clear(T &a){T().swap(a);}
int main()
{
int n,m,K,A,B,u,v;
cin>>n>>m>>A>>B;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
G[u].push_back(v);
}
cin>>K;
for(int i=0;i<K;i++)
{
scanf("%d%d",&u,&v);
msk[u]|=1<<i;w[u]+=v;
}
for(int S=1;S<(1<<K);S++)
{
for(int u=1;u<=n;u++)
for(int v=1;v<=n;v++)
du[u][v]=vis[u][v]=0,G2[u][v].clear();
for(int u=1;u<=n;u++)
for(int v=1;v<=n;v++)
{
f[S][u][v]=-INF;
if(msk[u]&S || msk[v]&S){good[u][v]=0;continue;}
good[u][v]=1;
for(int tu:G[u])
{
if(!(msk[tu]&S)) G2[v][tu].emplace_back(u,v),du[u][v]++;
else if((S&msk[tu])==msk[tu]) f[S][u][v]=max(f[S][u][v],w[tu]-f[S-msk[tu]][v][tu]);
}
}
for(int u=1;u<=n;u++)
for(int v=1;v<=n;v++)
if(good[u][v] && !du[u][v]) que.emplace(u,v);
while(!que.empty())
{
pii p=que.front();que.pop();
int u=p.first,v=p.second;
vis[u][v]=1;
for(pii p:G2[u][v])
{
int tu=p.first,tv=p.second;
f[S][tu][tv]=max(f[S][tu][tv],-f[S][u][v]);
if(!(--du[tu][tv])) que.emplace(tu,tv);
}
}
clear(pque);
for(int u=1;u<=n;u++)
for(int v=1;v<=n;v++)
if(good[u][v] && !vis[u][v]) pque.emplace(u,v,f[S][u][v]);
while(!pque.empty())
{
node t=pque.top();pque.pop();
if(vis[t.u][t.v]) continue;
int u=t.u,v=t.v;
// if(f[S][u][v]<0) break;
que.emplace(u,v);
while(!que.empty())
{
pii p=que.front();que.pop();
int u=p.first,v=p.second;
vis[u][v]=1;
for(pii p:G2[u][v])
{
int tu=p.first,tv=p.second;
if(f[S][tu][tv]<-f[S][u][v]) pque.emplace(tu,tv,f[S][tu][tv]=-f[S][u][v]);
if(!(--du[tu][tv])) que.emplace(tu,tv);
}
}
}
for(int u=1;u<=n;u++)
for(int v=1;v<=n;v++)
if(good[u][v] && !vis[u][v]) f[S][u][v]=0;
}
cout<<f[(1<<K)-1][A][B]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 2ms
memory: 3884kb
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: 3492kb
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: 4ms
memory: 5816kb
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:
1990966869
result:
wrong answer 1st numbers differ - expected: '132484345', found: '1990966869'