QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389250#4363. Branch AssignmentTWTP_TCTF#WA 3ms4600kbC++202.1kb2024-04-14 08:09:482024-04-14 08:09:49

Judging History

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

  • [2024-04-14 08:09:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4600kb
  • [2024-04-14 08:09:48]
  • 提交

answer

#include<iostream>
#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define rep(i, a, b) for(int i = a ; i < b ; i ++)
#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int N = 5e3 + 5;

vector<pair<int, int>> g[N], rg[N];
int n, b, s, r;

vector<ll> dij(int start, vector<pair<int, int>> g[N]){
    vector<ll> dist(n, 1e18 );
    dist[start] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push({0, start});
    while (pq.size()){
        ll v = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(v != dist[node])
            continue;
        for(auto &neg: g[node]){
            if(v + neg.second < dist[neg.first]){
                dist[neg.first] = v + neg.second;
                pq.push({v + neg.second, neg.first});
            }
        }
    }
    return dist;
}
void doWork() {
    cin >> n >> b >> s >> r;
    for(int i = 0; i < r; i++){
        int u, v, l;
        cin >> u >> v >> l;
        u--, v--;
        g[u].push_back({v, l});
        rg[v].push_back({u, l});
    }
    vector<ll> d1 = dij(b, g);
    vector<ll> d2 = dij(b, rg);
    vector<ll> values;
    for(int i = 0; i < b; i++){
        values.push_back(d1[i] + d2[i]);
    }
    sort(values.rbegin(), values.rend());
    vector<pair<ll, int>> st;
    for(int i = 0; i < s; i++) {
        st.push_back({0, 0});
    }
    ll ans = 0;
    for(int i = 0; i < b; i++){
        ll min = 1e18, best = -1;
       for(int j = 0; j < s; j++){
           ll add = st[j].first + st[j].second * values[i];
           if(add < min){
               min = add;
               best = j;
           }
       }
       ans += min;
       st[best].first += values[i];
       st[best].second++;
    }
    cout << ans;
}

int main() {
    IO
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
        //  cout << "Case #" << i << ": ";
        doWork();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3872kb

input:

5 4 2 10
5 2 1
2 5 1
3 5 5
4 5 0
1 5 1
2 3 1
3 2 5
2 4 5
2 1 1
3 4 2

output:

13

result:

ok single line: '13'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

5 4 2 10
5 2 1
2 5 1
3 5 5
4 5 10
1 5 1
2 3 1
3 2 5
2 4 5
2 1 1
3 4 2

output:

24

result:

ok single line: '24'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

5 4 3 8
1 5 15
5 1 15
2 5 2
5 2 3
3 5 1
5 3 1
4 5 2
5 4 0

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

2 1 1 2
1 2 5
2 1 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

9 4 2 11
1 2 1
2 3 2
3 4 3
4 6 4
6 8 5
8 9 6
9 7 7
7 5 8
5 8 8
7 6 9
6 1 10

output:

304

result:

ok single line: '304'

Test #6:

score: -100
Wrong Answer
time: 3ms
memory: 4600kb

input:

5000 4999 2 9998
1 2 10000
2 1 10000
2 3 10000
3 2 10000
3 4 10000
4 3 10000
4 5 10000
5 4 10000
5 6 10000
6 5 10000
6 7 10000
7 6 10000
7 8 10000
8 7 10000
8 9 10000
9 8 10000
9 10 10000
10 9 10000
10 11 10000
11 10 10000
11 12 10000
12 11 10000
12 13 10000
13 12 10000
13 14 10000
14 13 10000
14 15...

output:

624500075000000

result:

wrong answer 1st lines differ - expected: '589335814500000', found: '624500075000000'