답안 #842080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842080 2023-09-02T11:20:16 Z I_love_Hoang_Yen 봉쇄 시간 (IOI23_closing) C++17
0 / 100
108 ms 33444 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using Graph = vector<vector<pair<int,ll>>>;

void dfs(int u, int fu, const Graph& g, vector<ll>& dists) {
    for (auto [v, w] : g[u]) {
        if (v == fu) continue;
        assert(dists[v] < 0);

        dists[v] = dists[u] + w;
        dfs(v, u, g, dists);
    }
}

vector<ll> get_dists(int u, const Graph& g) {
    int n = g.size();
    vector<ll> dists(n, -1);
    dists[u] = 0;

    dfs(u, -1, g, dists);
    return dists;
}

// dists(x, y) > 2*k
int sub1(int n, const Graph& g, ll k,
        const vector<ll>& distsX,
        const vector<ll>& distsY) {
    vector<ll> dists;
    for (int i = 0; i < n; ++i) {
        dists.push_back(min(distsX[i], distsY[i]));
    }
    sort(dists.begin(), dists.end());

    int res = 0;
    for (auto d : dists) {
        if (d > k) break;
        k -= d;
        ++res;
    }
    return res;
}

// linear graph
int sub4(int n, int k, vector<ll> distsX, vector<ll> distsY) {
    vector<ll> dx, dy;
    for (int i = 0; i < n; ++i) {
        if (distsX[i] <= distsY[i]) {
            dx.push_back(distsX[i]);
        } else {
            dy.push_back(distsY[i]);
        }
    }
    sort(dx.begin(), dx.end());
    sort(dy.begin(), dy.end());
    int res = 0;
    for (int cx = 0; cx <= (int) dx.size(); ++cx) {
        int can = k, cur = 0;
        for (int i = 0; i < cx; ++i) {
            if (can >= dx[i]) {
                ++cur;
                can -= dx[i];
            } else break;
        }
        for (int i = 0; i < (int) dy.size(); ++i) {
            if (can >= dy[i]) {
                ++cur;
                can -= dy[i];
            } else break;
        }

        res = max(res, cur);
    }
    return res;
}

int max_score(int n, int X, int Y, long long K,
              vector<int> U, vector<int> V, vector<int> W) {
    Graph g(n);
    assert(int(U.size()) == n-1);
    assert(int(V.size()) == n-1);
    assert(int(W.size()) == n-1);
    for (int i = 0; i < n - 1; i++) {
        int u = U[i];
        int v = V[i];
        int w = W[i];
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }

    auto distsX = get_dists(X, g);
    auto distsY = get_dists(Y, g);
    
    return sub4(n, K, distsX, distsY);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 512 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 33444 KB 1st lines differ - on the 1st token, expected: '451', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '17'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '17'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '17'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 512 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 512 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 512 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 512 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 512 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -