QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#729119#8038. Hammer to FallEndPBWA 2ms9940kbC++202.0kb2024-11-09 16:31:132024-11-09 16:31:15

Judging History

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

  • [2024-11-09 16:31:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9940kb
  • [2024-11-09 16:31:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define N 100010
#define M 200010
#define B 1200
#define P 998244353

inline int read()
{
    int x=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while('0'<=c&&c<'9') {
        x=(x<<3)+(x<<1)+(c^48);
        c=getchar();
    }
    return x;
}

struct edg {
    int v;
    ll w,dp;
    bool operator<(const edg& oth)const {
        return dp>oth.dp;
    }
};
vector<edg> mp[N],big[N];
int du[N];

int n,m,q;
int a[N],b[N];
ll dp[N];

priority_queue<edg> pq[N];

void solve()
{
    n=read(),m=read(),q=read();
    for(int i=1; i<=n; ++i) a[i]=read();
    for(int i=1,u,v,w; i<=m; ++i) {
        u=read(),v=read(),w=read();
        mp[u].emplace_back(edg {v,w,0ll});
        mp[v].emplace_back(edg {u,w,0ll});
        du[u]++;
        du[v]++;
    }
    for(int i=1; i<=q; ++i) b[i]=read();

    for(int i=1; i<=n; ++i) for(const edg& e:mp[i]) {
            if(du[e.v]>B) big[i].emplace_back(e.v);
        }
    for(int i=1; i<=n; ++i) if(du[i]>B) {
            for(const edg& e:mp[i]) pq[i].push(edg {e.v,0,e.w});
        }
    for(int i=q; i; --i) {
        int u=b[i];
        if(du[u]<=B) {
            dp[u]=1e18;
            for(const edg& e:mp[u]) dp[u]=min(dp[u],dp[e.v]+e.w);
        } else {
            while(!pq[u].empty()) {
                edg e=pq[u].top();
                if(dp[e.v]==e.w) {
                    dp[u]=e.dp;
                    break;
                } else pq[u].pop();
            }
        }

        for(const edg& e:big[u]) {
            pq[e.v].push(edg {u,dp[u],dp[u]+e.w});
        }
    }

    ll ans=0;
    for(int i=1; i<=q; ++i) {
        int u=b[i];
        ans=(ans+dp[u]*a[u]%P)%P;
        dp[u]=0;
    }
    cout<<ans;
}

signed main()
{
//    std::cin.tie(nullptr) -> sync_with_stdio(false);
    int T = 1;
//    std::cin >> T;
//    while(T--)
    solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 8420kb

input:

3 2 2
1 1 1
2 3 10
1 2 1
3 2

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 2ms
memory: 9940kb

input:

2 1 10
5000 5000
1 2 10000
1 2 2 1 2 2 1 1 1 2

output:

550000000

result:

ok single line: '550000000'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 8636kb

input:

10 10 10
5 14 99 14 18 4 58 39 48 60
2 4 4
6 9 56
10 8 34
7 5 96
1 3 26
3 7 92
6 8 4
5 1 72
7 6 39
7 2 93
8 8 9 10 2 2 5 9 2 3

output:

684

result:

wrong answer 1st lines differ - expected: '8810', found: '684'