QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#400106 | #6331. Jewel Game | manizare | WA | 1ms | 4024kb | C++20 | 2.8kb | 2024-04-26 23:03:45 | 2024-04-26 23:03:46 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define ld long double
#define aint(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = (1<<11)+10 , maxq = 32, inf = 1e18+10 , lg = 19 ,sq = 707 ,mod = 1e18+7 ;
int dp2[maxn][33][33] , dp[33][33] ;
int n , m, a , b , k , dd[33] , d[33][33] , x[33] , w[33] ,mark[33][33] ;
priority_queue<pair<int,pii> > pq ;
queue <pii> q; ;
vector <int> G[44];
void upd(int x ,int y ){
for(int u : G[y]){
d[u][x]--;
if(d[u][x] == 0){
q.push({u,x}) ; mark[u][x] = 1;
dp[u][x] = max(dp[u][x] , -dp[x][y]) ;
pq.push({dp[u][x] , {u,x}});
}
if(mark[u][x] == 1)continue ;
dp[u][x] = max(dp[u][x] , -dp[x][y]) ;
pq.push({dp[u][x] , {u,x}});
}
}
void ch(){
while(sz(q)){
int v = q.front().F , u = q.front().S ;q.pop() ;
if(mark[v][u] == 1)continue ;
mark[v][u] = 1;
upd(v,u) ;
}
}
void sl(int ms){
rep(i , 1 , n){
rep(j , 1, n){
d[i][j] = dd[i] ;
dp[i][j] = -inf ;
mark[i][j]= 0;
}
}
while(sz(pq))pq.pop();
while(sz(q))q.pop();
rep(i ,0,k-1){
if(ms>>i&1){
rep(j , 1, n){
for(int u : G[x[i]]){
d[u][j]--;
if(d[u][j]==0){
q.push({u,j}) ;
}
dp[u][j] = max(dp[u][j] , -dp2[ms^(1<<i)][j][x[i]]+w[i]) ;
}
}
}
}
ch();
rep(i , 1 , n)rep(j , 1 , n)pq.push({dp[i][j] , {i,j}}) ;
while(sz(pq)){
int v = pq.top().S.F , u= pq.top().S.S;pq.pop() ;
if(mark[v][u] == 1)continue ;
if(dp[v][u] <= 0){
break ;
}
mark[v][u] = 1;
upd(v,u);
ch();
}
ch();
rep(i , 1,n)rep(j , 1 ,n)if(mark[i][j] == 0)dp[i][j] =0 ;
rep(i , 1 , n)rep(j , 1,n)dp2[ms][i][j] = dp[i][j] ;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> a >> b ;
rep(i , 1 , m){
int v , u ;
cin >> v >> u ;
G[u].pb(v);
dd[v]++;
}
cin >> k;
rep(i , 0 , k-1){
cin>> x[i]>> w[i] ;
}
rep(ms , 1 , (1<<k)-1){
sl(ms);
}
cout << dp2[(1<<k)-1][a][b] << "\n";
return 0 ;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3740kb
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: 1ms
memory: 4024kb
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: -100
Wrong Answer
time: 0ms
memory: 3612kb
input:
5 5 2 1 1 1 2 3 3 4 4 5 5 2 2 4 1000000 5 100000
output:
0
result:
wrong answer 1st numbers differ - expected: '1100000', found: '0'