Submission #842089

# Submission time Handle Problem Language Result Execution time Memory
842089 2023-09-02T11:40:41 Z cjoa Closing Time (IOI23_closing) C++17
8 / 100
105 ms 30724 KB
#include "closing.h"

#include <vector>
#include <algorithm>
#include <queue>

#include <iostream>

using namespace std;

using llong = long long;

const llong INF = 4e18;

struct Edge {
    int u, v, w;
    int opp(int x) const {
        return x == u ? v : u;
    }
};

vector<Edge> edges;
vector< vector<int> > tree;

llong K;
void dfs(int u, int p, llong t, vector<llong>& closing_times) {
    if (t > K)
        return;
    closing_times[u] = t;
    for (int eid : tree[u]) {
        int v = edges[eid].opp(u);
        if (v == p) continue;
        int w = edges[eid].w;
        dfs(v, u, t + w, closing_times);
    }
}

int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    ::K = K;
//  cerr << "K: " << K << endl;

    tree = vector< vector<int> >(N);
    for (int j = 0; j < N-1; j++) {
        int u = U[j], v = V[j], w = W[j];
        int eid = edges.size();
        edges.push_back({u, v, w});
        tree[u].push_back(eid);
        tree[v].push_back(eid);
    }

    // subtask1

    vector<llong> closing_timesX(N, INF);
    dfs(X, -1, 0, closing_timesX);

    vector<llong> closing_timesY(N, INF);
    dfs(Y, -1, 0, closing_timesY);

    priority_queue<llong> pq;
    llong sum = 0;
    for (int u = 0; u < N; ++u) {
        llong t = min(closing_timesX[u], closing_timesY[u]);
        if (t <= K) {
            pq.push(t);
            sum += t;
        }
    }

    while (sum > K) {
        llong t = pq.top(); pq.pop();
        sum -= t;
    }

    return pq.size();
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 24740 KB Output is correct
2 Correct 105 ms 30724 KB Output is correct
3 Correct 63 ms 6088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '30', found: '17'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '30', found: '17'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '30', found: '17'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -