QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420879#8038. Hammer to Fallfishy15WA 101ms16180kbC++141.6kb2024-05-25 02:47:202024-05-25 02:47:23

Judging History

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

  • [2024-05-25 02:47:23]
  • 评测
  • 测评结果:WA
  • 用时:101ms
  • 内存:16180kb
  • [2024-05-25 02:47:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

constexpr ll INF = 2e18;

ll bpow(ll a, ll b, ll m) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<ll> dist(n);
    vector<ll> guys(n);
    for(int i = 0; i < n; i++) {
        cin >> guys[i];
    }
    vector<vector<pair<int, ll>>> con(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        ll w;
        cin >> a >> b >> w;
        a--; b--;
        con[a].push_back({b, w});
        con[b].push_back({a, w});
    }
    vector<int> queries(q);
    map<int, int> first;
    for(int i = 0; i < q; i++) {
        cin >> queries[i];
        queries[i]--;
    }
    for(int i = 0; i < q; i++) {
        if(first.count(queries[i]) == 0)
            first[queries[i]] = i;
    }
    ll ans = 0;
    for(int time = q-1; time >= 0; time--) {
        int Q = queries[time];
        ll best = INF;
        for(auto next : con[Q]) {
            int nextId = next.first;
            ll cost = next.second;
            best = min(best, dist[nextId]+cost);
        }
        dist[Q] = best;
        if(time == first[Q])
            ans += dist[Q]*guys[Q];
    }
    // for(ll d : dist)
    //     cout << d << " ";
    // cout << endl;
    cout << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 0
Accepted
time: 0ms
memory: 3560kb

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:

8810

result:

ok single line: '8810'

Test #4:

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

input:

100 500 10000
89 61 65 85 89 2 32 97 13 70 29 86 68 74 84 64 54 39 26 84 56 95 73 11 70 26 60 40 84 58 68 33 65 71 55 2 11 71 49 85 14 59 38 11 60 8 81 78 27 32 52 49 35 94 62 72 64 50 12 45 77 74 92 67 92 38 81 39 12 29 60 70 53 33 25 60 7 83 4 85 47 32 13 58 85 86 44 68 44 1 81 62 97 7 66 62 5 16 ...

output:

609241

result:

ok single line: '609241'

Test #5:

score: -100
Wrong Answer
time: 101ms
memory: 16180kb

input:

100000 100000 100000
134299012 740620432 241626312 533601686 901212368 274154852 46613593 72208460 685661661 930069933 934386896 140544225 900179749 8735320 54649110 922673925 450551589 517879800 773426781 410723403 783459037 344315202 75310230 122339501 113898579 646500753 18238713 119326471 969272...

output:

-7775360003412130668

result:

wrong answer 1st lines differ - expected: '641103242', found: '-7775360003412130668'