답안 #839574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839574 2023-08-30T09:00:00 Z model_code Truck Driver (IOI23_deliveries) C++17
29 / 100
493 ms 61528 KB
// incorrect/sol_vp_fixed_guess2.cpp

#include "deliveries.h"
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
#include <random>
#include <queue>

using namespace std;

struct graph{
    vector<long long> dist;
    vector<int> cnt;
    long long weight_sum;
    int C;
};

vector<vector<pair<int, long long>>> g;
vector<int> ord, dist, under;
vector<bool> vis;
vector<graph> gds;

void dfs0(int x, int d){
    vis[x] = true;
    dist[x] = d;
    under[x] = 1;
    for(auto [y, w] : g[x]){
        if(!vis[y]){
            dfs0(y, d + 1);
            under[x] += under[y];
        }
    }
}

int get_c(int x, int p, int n){
    for(auto [y, w] : g[x]){
        if(y != p && under[y]*2 > n){
            return get_c(y, x, n);
        }
    }
    return x;
}

long long dfs(graph &gd, int x, long long d){
    vis[x] = true;
    gd.dist[x] = d;
    long long res = gd.cnt[x];
    for(auto [y, w] : g[x]){
        if(!vis[y]){
            long long tmp = dfs(gd, y, w + d);
            gd.weight_sum += w * tmp;
            res += tmp;
        }
    }
    return res;
}

void update(graph &gd, int x, int c){
    if(x == 0) ++c;
    gd.weight_sum += (c - gd.cnt[x]) * gd.dist[x];
    gd.cnt[x] = c;
}

void init(int N, std::vector<int> U, std::vector<int> V, std::vector<int> T, std::vector<int> W) {
	g.resize(N);
    under.resize(N);
    dist.resize(N);
    for(int i = 0; i < N-1; i++){
        g[U[i]].emplace_back(V[i], T[i]);
        g[V[i]].emplace_back(U[i], T[i]);
    }
  
    // near centroid
    vis.assign(N, false);
    dfs0(0, 0);
    int c = get_c(0, -1, N);
    vis.assign(N, false);
    dfs0(c, 0);
    // end

    const int B = min(N, 5000000/N);

    mt19937 gen(42);
    ord.resize(N);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [](int a, int b) -> bool { return dist[a] < dist[b]; });
    ord.resize(B);

    gds.resize(B);

    W[0]++;
    for(int i = 0; i < B; i++){
        vis.assign(N, false);
        gds[i].C = ord[i];
        gds[i].weight_sum = 0;
        gds[i].dist.resize(N);
        gds[i].cnt = W;
        dfs(gds[i], ord[i], 0);
    }

    return;
}

long long max_time(int S, int X) {
    long long res = 1e18;
    for(int i = 0; i < (int)gds.size(); i++){
        update(gds[i], S, X);
        res = min(res, gds[i].weight_sum);
        // cout << "i: " << i << ' ' << gds[i].weight_sum << endl;
    }
    return res * 2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 7576 KB Output is correct
2 Correct 83 ms 7368 KB Output is correct
3 Correct 80 ms 7624 KB Output is correct
4 Correct 82 ms 7520 KB Output is correct
5 Correct 70 ms 7780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 10 ms 7092 KB Output is correct
3 Correct 11 ms 7108 KB Output is correct
4 Correct 43 ms 12264 KB Output is correct
5 Correct 31 ms 12284 KB Output is correct
6 Correct 40 ms 12276 KB Output is correct
7 Correct 35 ms 12272 KB Output is correct
8 Correct 36 ms 12296 KB Output is correct
9 Correct 37 ms 12300 KB Output is correct
10 Correct 32 ms 12316 KB Output is correct
11 Correct 40 ms 12240 KB Output is correct
12 Correct 35 ms 12248 KB Output is correct
13 Correct 34 ms 12252 KB Output is correct
14 Correct 44 ms 12316 KB Output is correct
15 Correct 37 ms 12300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 7576 KB Output is correct
2 Correct 83 ms 7368 KB Output is correct
3 Correct 80 ms 7624 KB Output is correct
4 Correct 82 ms 7520 KB Output is correct
5 Correct 70 ms 7780 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 93 ms 12288 KB Output is correct
8 Incorrect 493 ms 60984 KB 3rd lines differ - on the 1st token, expected: '114626592', found: '114681364'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 7576 KB Output is correct
2 Correct 83 ms 7368 KB Output is correct
3 Correct 80 ms 7624 KB Output is correct
4 Correct 82 ms 7520 KB Output is correct
5 Correct 70 ms 7780 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 71 ms 12344 KB Output is correct
8 Incorrect 365 ms 61528 KB 3rd lines differ - on the 1st token, expected: '18667233496', found: '23211950128'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 7576 KB Output is correct
2 Correct 83 ms 7368 KB Output is correct
3 Correct 80 ms 7624 KB Output is correct
4 Correct 82 ms 7520 KB Output is correct
5 Correct 70 ms 7780 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 10 ms 7092 KB Output is correct
8 Correct 11 ms 7108 KB Output is correct
9 Correct 43 ms 12264 KB Output is correct
10 Correct 31 ms 12284 KB Output is correct
11 Correct 40 ms 12276 KB Output is correct
12 Correct 35 ms 12272 KB Output is correct
13 Correct 36 ms 12296 KB Output is correct
14 Correct 37 ms 12300 KB Output is correct
15 Correct 32 ms 12316 KB Output is correct
16 Correct 40 ms 12240 KB Output is correct
17 Correct 35 ms 12248 KB Output is correct
18 Correct 34 ms 12252 KB Output is correct
19 Correct 44 ms 12316 KB Output is correct
20 Correct 37 ms 12300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 93 ms 12288 KB Output is correct
23 Incorrect 493 ms 60984 KB 3rd lines differ - on the 1st token, expected: '114626592', found: '114681364'
24 Halted 0 ms 0 KB -