답안 #839567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839567 2023-08-30T08:59:41 Z model_code Truck Driver (IOI23_deliveries) C++17
29 / 100
4500 ms 21436 KB
// correct/solution-subtask2.cpp

#include "deliveries.h"

#include <iostream>
#include <vector>

#define MAXN 101000

using namespace std;

long long N, centroid, allSumW, ans;
vector<int> edge[MAXN];
long long W[MAXN];
long long sumW[MAXN];
long long T[MAXN];

bool dfs(int x){
    sumW[x] = W[x];
    bool flipped = false;
    for(int i : edge[x]){
        flipped |= dfs(i);
        sumW[x] += sumW[i];
    }

    if(centroid==-1 && sumW[x] >= (allSumW + 1)/2){
        centroid = x;
        flipped = true;
    }

    if(flipped){
        ans += (allSumW - sumW[x]) * T[x];
    } else {
        ans += sumW[x] * T[x];
    }

    return flipped;
}

void init(int NN, std::vector<int> UU, std::vector<int> VV, std::vector<int> TT, std::vector<int> WW){
	N = NN;
    vector<vector<pair<int,int>>> e(N);
	for (int i=0; i+1<N; ++i) {
		e[UU[i]].push_back({VV[i], TT[i]});
		e[VV[i]].push_back({UU[i], TT[i]});
	}
	vector<int> AA(N, -1), q = {0};
	vector<int> TTT(N, 0);
	for (int i = 0; i < (int)q.size(); ++i) {
		int u = q[i];
		for (auto [v, t] : e[u]) {
			if (AA[u] == v) continue;
			AA[v] = u;
			TTT[v] = t;
			q.push_back(v);
		}
	}

    for(int i=0; i<N-1; i++){
		edge[AA[i+1]].push_back(i+1);
        T[i+1] = TTT[i+1];
	}
	for(int i=0; i<N; i++){
		W[i] = WW[i];
	}
	W[0]++;

    for(int i=0; i<N; i++)
        allSumW += W[i];
}

long long max_time(int S, int X){
	if(S==0) X++;

    allSumW -= W[S];

	W[S] = X;
    allSumW += W[S];

    ans = 0; centroid = -1; dfs(0);
    return 2*ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 10024 KB Output is correct
2 Correct 89 ms 9852 KB Output is correct
3 Correct 80 ms 10104 KB Output is correct
4 Correct 79 ms 10004 KB Output is correct
5 Correct 74 ms 10004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 8 ms 2772 KB Output is correct
3 Correct 9 ms 2772 KB Output is correct
4 Correct 12 ms 2772 KB Output is correct
5 Correct 9 ms 2792 KB Output is correct
6 Correct 11 ms 2892 KB Output is correct
7 Correct 9 ms 2864 KB Output is correct
8 Correct 12 ms 2872 KB Output is correct
9 Correct 10 ms 2896 KB Output is correct
10 Correct 12 ms 2900 KB Output is correct
11 Correct 9 ms 2844 KB Output is correct
12 Correct 9 ms 2772 KB Output is correct
13 Correct 9 ms 2840 KB Output is correct
14 Correct 17 ms 2884 KB Output is correct
15 Correct 15 ms 2884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 10024 KB Output is correct
2 Correct 89 ms 9852 KB Output is correct
3 Correct 80 ms 10104 KB Output is correct
4 Correct 79 ms 10004 KB Output is correct
5 Correct 74 ms 10004 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 26 ms 2832 KB Output is correct
8 Correct 1843 ms 4612 KB Output is correct
9 Execution timed out 4582 ms 18684 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 10024 KB Output is correct
2 Correct 89 ms 9852 KB Output is correct
3 Correct 80 ms 10104 KB Output is correct
4 Correct 79 ms 10004 KB Output is correct
5 Correct 74 ms 10004 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 28 ms 2916 KB Output is correct
8 Correct 2482 ms 5076 KB Output is correct
9 Execution timed out 4551 ms 21436 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 10024 KB Output is correct
2 Correct 89 ms 9852 KB Output is correct
3 Correct 80 ms 10104 KB Output is correct
4 Correct 79 ms 10004 KB Output is correct
5 Correct 74 ms 10004 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 8 ms 2772 KB Output is correct
8 Correct 9 ms 2772 KB Output is correct
9 Correct 12 ms 2772 KB Output is correct
10 Correct 9 ms 2792 KB Output is correct
11 Correct 11 ms 2892 KB Output is correct
12 Correct 9 ms 2864 KB Output is correct
13 Correct 12 ms 2872 KB Output is correct
14 Correct 10 ms 2896 KB Output is correct
15 Correct 12 ms 2900 KB Output is correct
16 Correct 9 ms 2844 KB Output is correct
17 Correct 9 ms 2772 KB Output is correct
18 Correct 9 ms 2840 KB Output is correct
19 Correct 17 ms 2884 KB Output is correct
20 Correct 15 ms 2884 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 26 ms 2832 KB Output is correct
23 Correct 1843 ms 4612 KB Output is correct
24 Execution timed out 4582 ms 18684 KB Time limit exceeded
25 Halted 0 ms 0 KB -