QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#131332#6331. Jewel GameEnergy_is_not_overWA 1ms3776kbC++175.7kb2023-07-26 22:43:442023-07-26 22:43:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-26 22:43:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2023-07-26 22:43:44]
  • 提交

answer

//
// Created by Barichek on 21.07.2023 15:43:48
//

#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(), a.end()
#define len(a) (int) (a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

#ifdef Energy_is_not_over
#define DEBUG for (bool ____DEBUG = true; ____DEBUG; ____DEBUG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl

template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }

#else
#define DEBUG while (false)
#define LOG(...)
#endif

const int max_n = 30, inf = 1000111222;

const int max_k=10;

inline bool get_bit(ll mask,int bit)
{
    return (mask>>bit)&1;
}

void maximize(int& a,int b)
{
    if (a<b){
        a=b;
    }
}

void minimize(int& a,int b)
{
    if (a>b){
        a=b;
    }
}

int n,m,a,b;
int k;

bool edge[max_n][max_n];
int vertex_cost[max_n];
int vertex_id_in_mask[max_k];
int pos_in_mask_for_vertex[max_n];

int global_mask;
int dp[(1ll<<max_k)][2][max_n][max_n];
int cur_outs_A[max_n][max_n];
bool cur_calculated_B[max_n][max_n];

inline void process_cur_A(int i,int j)
{
    if (dp[global_mask][0][i][j]==-inf){
        dp[global_mask][0][i][j]=0;
    }
    else{
        if (pos_in_mask_for_vertex[j]==-1 || get_bit(global_mask,pos_in_mask_for_vertex[j])){
            for (int k=0;k<n;k++){
                if (edge[k][j]){
                    minimize(dp[global_mask][1][i][k],dp[global_mask][0][i][j]);
                }
            }
        }
    }
    LOG("final value of dp[global_mask][0][i][j]",i,j,dp[global_mask][0][i][j]);
    cur_outs_A[i][j]=inf;
}

int main() {
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a>>b;
    a--;
    b--;
    for (int i=0;i<n;i++){
        pos_in_mask_for_vertex[i]=-1;
    }
    for (int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        edge[u][v]=1;
    }
    cin>>k;
    LOG(k);
    for (int i=0;i<k;i++){
        int x,w;
        cin>>x>>w;
        x--;
        vertex_id_in_mask[i]=x;
        vertex_cost[x]=w;
        pos_in_mask_for_vertex[x]=i;
    }
    for (int i=0;i<(1ll<<k);i++){
        for (int j=0;j<n;j++){
            for (int k=0;k<n;k++){
                dp[i][0][j][k]=-inf;
                dp[i][1][j][k]=+inf;
            }
        }
    }
    for (global_mask=(1ll<<k)-1;global_mask>=0;global_mask--){
        LOG(bitset<4>(global_mask));
        {
            for (int i=0;i<n;i++){
                for (int j=0;j<n;j++){
                    for (int k=0;k<n;k++){
                        if (edge[i][k] && (pos_in_mask_for_vertex[k]!=-1 && !get_bit(global_mask,pos_in_mask_for_vertex[k]))){
                            maximize(dp[global_mask][0][i][j],dp[global_mask+(1ll<<pos_in_mask_for_vertex[k])][1][k][j]+vertex_cost[k]);
                        }
                    }
                }
            }
            for (int i=0;i<n;i++){
                for (int j=0;j<n;j++){
                    for (int k=0;k<n;k++){
                        if (edge[j][k] && (pos_in_mask_for_vertex[k]!=-1 && !get_bit(global_mask,pos_in_mask_for_vertex[k]))){
                            minimize(dp[global_mask][1][i][j],dp[global_mask+(1ll<<pos_in_mask_for_vertex[k])][0][i][k]-vertex_cost[k]);
                        }
                    }
                }
            }
        }

        {
            memset(cur_outs_A,0,sizeof(cur_outs_A));
            for (int i=0;i<n;i++){
                for (int j=0;j<n;j++){
                    for (int k=0;k<n;k++){
                        if (edge[i][k] && (pos_in_mask_for_vertex[k]==-1 || get_bit(global_mask,pos_in_mask_for_vertex[k]))){
                            cur_outs_A[i][j]++;
                        }
                    }
                }
            }
            for (int i=0;i<n;i++){
                for (int j=0;j<n;j++){
                    if (cur_outs_A[i][j]==0){
                        process_cur_A(i,j);
                    }
                }
            }
            memset(cur_calculated_B,0,sizeof(cur_calculated_B));
            while (1){
                int B_i=-1,B_j=-1;
                for (int i=0;i<n;i++){
                    for (int j=0;j<n;j++){
                        if (!cur_calculated_B[i][j] && ((B_i==-1 && B_j==-1) || dp[global_mask][1][i][j]<dp[global_mask][1][B_i][B_j])){
                            B_i=i;
                            B_j=j;
                        }
                    }
                }
                if (B_i==-1 && B_j==-1){
                    break;
                }
                if (dp[global_mask][1][B_i][B_j]==+inf){
                    dp[global_mask][1][B_i][B_j]=0;
                }
                LOG("final value of dp[global_mask][1][i][j]",B_i,B_j,dp[global_mask][1][B_i][B_j]);
                cur_calculated_B[B_i][B_j]=1;
                if (pos_in_mask_for_vertex[B_i]==-1 || get_bit(global_mask,pos_in_mask_for_vertex[B_i])){
                    for (int k=0;k<n;k++){
                        if (edge[k][B_i]){
                            maximize(dp[global_mask][0][k][B_j],dp[global_mask][1][B_i][B_j]);
                            if ((--cur_outs_A[k][B_j])==0){
                                process_cur_A(k,B_j);
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<dp[0][0][a][b]<<"\n";
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3776kb

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:

0

result:

wrong answer 1st numbers differ - expected: '46', found: '0'