Submission #1056662

# Submission time Handle Problem Language Result Execution time Memory
1056662 2024-08-13T10:30:42 Z TheQuantiX Closing Time (IOI23_closing) C++17
43 / 100
135 ms 34420 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll INF = 1000000000000000000LL;

ll n, m, q, k, x, y, a, b, c, d;
// unordered_map<ll, ll> G1[200000];
vector< pair<ll, ll> > G[200000];

void dfs(ll x, vector<ll> &dist, ll d) {
    // cout << "Enter " << x << endl;
    // cout << '\t' << dist[x] << ' ' << d << endl;
    dist[x] = d;
    for (auto i : G[x]) {
        if (dist[i.first] == INF) {
            dfs(i.first, dist, d + i.second);
        }
    }
    // cout << "Exit " << x << endl;
}

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    x = X;
    y = Y;
    k = K;
    for (auto i = 0; i < n - 1; i++) {
        // G[U[i]][V[i]] = W[i];
        // G[V[i]][U[i]] = W[i];
        G[U[i]].push_back({V[i], W[i]});
        G[V[i]].push_back({U[i], W[i]});
    }
    vector<ll> dist1(n, INF), dist2(n, INF);
    dfs(x, dist1, 0);
    dfs(y, dist2, 0);
    if (dist1[y] > k * 2) {
        vector<ll> vec;
        for (int i = 0; i < n; i++) {
            // cout << dist1[i] << ' ';
            vec.push_back(dist1[i]);
        }
        // cout << '\n';
        for (int i = 0; i < n; i++) {
            vec.push_back(dist2[i]);
        }
        sort(vec.begin(), vec.end());
        ll cnt = 0;
        for (auto i : vec) {
            // cout << i << '\n';
            if (k >= i) {
                cnt++;
                k -= i;
            }
            else {
                break;
            }
        }
        for (auto i = 0; i < n; i++) {
            // G[U[i]][V[i]] = W[i];
            // G[V[i]][U[i]] = W[i];
            G[i].clear();
        }
        return cnt;
    }
    ll cnt = 2;
    array< deque<ll>, 4 > v;
    for (int i = x + 1; i < n; i++) {
        v[0].push_back(dist1[i]);
    }
    for (int i = y + 1; i < n; i++) {
        v[1].push_back(dist2[i]);
    }
    for (int i = x - 1; i >= 0; i--) {
        v[2].push_back(dist1[i]);
    }
    for (int i = y - 1; i >= 0; i--) {
        v[3].push_back(dist2[i]);
    }
    vector<ll> alr(n, 0);
    array< ll, 4 > p = {0, 0, 0, 0};
    while (1) {
        // cout << "DEBUG" << endl;
        array< ll, 4 > costs;
        for (int i = 0; i < 4; i++) {
            // cout << i << endl;
            if (p[i] == v[i].size()) {
                costs[i] = INF;
                // cout << costs[i] << ' ';
                continue;
            }
            costs[i] = v[i][p[i]];
            ll idx = -1;
            if (i == 0) {
                idx = x + p[i] + 1;
            }
            else if (i == 1) {
                idx = y + p[i] + 1;
            }
            else if (i == 2) {
                idx = x - p[i] - 1;
            }
            else {
                idx = y - p[i] - 1;
            }
            // cout << idx << ' ' << alr[idx] << ' ' << costs[i] << endl;
            costs[i] -= alr[idx];
            // cout << costs[i] << ' ';
        }
        // cout << '\n';
        // for (auto i : alr) {
        //     cout << i << ' ';
        // }
        // cout << '\n';
        ll idx = min_element(costs.begin(), costs.end()) - costs.begin();
        ll val = costs[idx];
        // cout << val << ' ' << k << '\n';
        if (k < val) {
            break;
        }
        k -= val;
        cnt++;
        ll idx1 = -1;
        if (idx == 0) {
            idx1 = x + p[idx] + 1;
        }
        else if (idx == 1) {
            idx1 = y + p[idx] + 1;
        }
        else if (idx == 2) {
            idx1 = x - p[idx] - 1;
        }
        else {
            idx1 = y - p[idx] - 1;
        }
        alr[idx1] += costs[idx];
        p[idx]++;
    }
    for (auto i = 0; i < n; i++) {
        // G[U[i]][V[i]] = W[i];
        // G[V[i]][U[i]] = W[i];
        G[i].clear();
    }
    return cnt;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:89:22: warning: comparison of integer expressions of different signedness: 'std::array<long long int, 4>::value_type' {aka 'long long int'} and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             if (p[i] == v[i].size()) {
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4952 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 95 ms 31652 KB Output is correct
2 Correct 135 ms 34420 KB Output is correct
3 Correct 51 ms 7740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4988 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4988 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 5468 KB Output is correct
27 Correct 2 ms 5468 KB Output is correct
28 Correct 3 ms 5468 KB Output is correct
29 Correct 3 ms 5448 KB Output is correct
30 Correct 2 ms 5468 KB Output is correct
31 Correct 2 ms 5472 KB Output is correct
32 Correct 3 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4952 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 1 ms 4952 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 1 ms 4952 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 1 ms 4952 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 1 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -