Submission #1055969

# Submission time Handle Problem Language Result Execution time Memory
1055969 2024-08-13T06:52:32 Z Triseedot Closing Time (IOI23_closing) C++17
0 / 100
86 ms 31872 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include <debug.h>
#else
#define debug(...) 42
#endif

using ll = long long;
#define all(v) v.begin(), v.end()
#define len(v) int(v.size())

const ll INF = 1e18;

int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
    vector<vector<pair<int, int>>> g(N);
    for (int i = 0; i < N - 1; i++) {
        g[V[i]].push_back({U[i], W[i]});
        g[U[i]].push_back({V[i], W[i]});
    }
    
    auto calc_dist = [&] (int v_s) {
        vector<int> dist(N, INF);
        dist[v_s] = 0;
        function<void(int, int)> dfs = [&] (int v, int pr) {
            for (auto [u, w] : g[v]) {
                if (u == pr) continue;
                dist[u] = dist[v] + w;
                dfs(u, v);
            }
        };
        dfs(v_s, -1);
        return dist;
    };
    
    vector dist_x = calc_dist(X), dist_y = calc_dist(Y);
    
    sort(all(dist_x)); sort(all(dist_y));
    vector<ll> cost_x(N + 1, 0), cost_y(N + 1, 0);
    for (int i = 0; i < N; i++) {
        cost_x[i + 1] = cost_x[i] + dist_x[i];
        cost_y[i + 1] = cost_y[i] + dist_y[i];
    }
    
    int j = 0;
    int ans = 0;
    for (int i = N; i >= 0; i--) {
        while (cost_x[i] + cost_y[j + 1] <= K) j++;
        if (cost_x[i] + cost_y[j] <= K) {
            ans = max(ans, i + j);
        }
    }
    
    return ans;
}

Compilation message

closing.cpp: In lambda function:
closing.cpp:24:29: warning: overflow in conversion from 'll' {aka 'long long int'} to 'std::vector<int>::value_type' {aka 'int'} changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   24 |         vector<int> dist(N, INF);
      |                             ^~~
# 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 86 ms 31872 KB 1st lines differ - on the 1st token, expected: '451', found: '649949'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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: '24'
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 -