QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400140#6331. Jewel GamemanizareWA 1ms6652kbC++202.7kb2024-04-27 00:54:272024-04-27 00:54:27

Judging History

你现在查看的是最新测评结果

  • [2024-04-27 00:54:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6652kb
  • [2024-04-27 00:54:27]
  • 提交

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(mark[u][x] == 1)continue ;
        if(d[u][x] == 0){
           q.push({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(dp[v][u] <= 0){
            break ;
        }
        if(mark[v][u] == 1)continue ;
        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 ;
}
/*


*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3736kb

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: 4036kb

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: 3676kb

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: 0ms
memory: 6652kb

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'