Submission #1038019

# Submission time Handle Problem Language Result Execution time Memory
1038019 2024-07-29T12:08:55 Z Zicrus Closing Time (IOI23_closing) C++17
8 / 100
103 ms 42516 KB
#include <bits/stdc++.h>
#include "closing.h"
using namespace std;

typedef long long ll;

vector<vector<pair<ll, ll>>> adj;
vector<ll> parent, depth;
vector<ll> distX, distY, totX;
vector<bool> vstX, vstY;

void root(ll cur, ll par, ll dep) {
    parent[cur] = par;
    depth[cur] = dep;
    for (auto &e : adj[cur]) {
        if (e.second == par) continue;
        root(e.second, cur, dep+1);
    }
}

ll mxFromMid(ll mid, ll k) {
    ll n = adj.size();

    priority_queue<pair<ll, ll>> q, q2;

    for (int i = 0; i < n; i++) {
        if (vstX[i] && vstY[i]) continue;
        if (vstX[i]) {
            q.push({-max(0ll, distY[i]-distX[i]), i});
        }
        else if (vstY[i]) {
            q.push({-max(0ll, distX[i]-distY[i]), i});
        }
        else {
            q.push({-min(distX[i], distY[i]), i});
        }
    }
    ll res = 0;
    ll k1 = k;
    while (!q.empty()) {
        ll dist = -q.top().first; q.pop();
        if (dist > k1) return res;
        k1 -= dist;
        res++;
    }
    return res;
}

int max_score(int n, int x, int y, ll k, vector<int> u, vector<int> v, vector<int> w) {
    priority_queue<pair<ll, ll>> finalQ;
    adj = vector<vector<pair<ll, ll>>>(n);
    for (int i = 0; i < w.size(); i++) {
        adj[u[i]].push_back({-w[i], v[i]});
        adj[v[i]].push_back({-w[i], u[i]});
    }

    distX = vector<ll>(n, 1ll << 62ll);
    distY = vector<ll>(n, 1ll << 62ll);
    totX = vector<ll>(n);
    vstX = vector<bool>(n);
    vstY = vector<bool>(n);
    parent = vector<ll>(n);
    depth = vector<ll>(n);
    priority_queue<pair<ll, ll>> q;
    distX[x] = distY[y] = 0;
    q.push({0, x});
    while (!q.empty()) {
        ll node = q.top().second; q.pop();
        if (vstX[node]) continue;
        vstX[node] = true;
        for (auto &e : adj[node]) {
            distX[e.second] = min(distX[e.second], distX[node] - e.first);
            if (distX[e.second] == distX[node] - e.first) {
                totX[e.second] = distX[e.second] + totX[node];
            }
            q.push({-distX[e.second], e.second});
        }
    }
    q.push({0, y});
    while (!q.empty()) {
        ll node = q.top().second; q.pop();
        if (vstY[node]) continue;
        vstY[node] = true;
        for (auto &e : adj[node]) {
            distY[e.second] = min(distY[e.second], distY[node] - e.first);
            q.push({-distY[e.second], e.second});
        }
    }
    root(x, -1, 0);

    // Naive
    for (int i = 0; i < n; i++) {
        finalQ.push({-min(distX[i], distY[i]), i});
    }
    ll res = 0;
    ll k1 = k;
    while (!finalQ.empty()) {
        ll dist = -finalQ.top().first; finalQ.pop();
        if (dist > k1) return res;
        k1 -= dist;
        res++;
    }

    // Check meetings
    ll mid = y;
    ll cost = totX[y];
    vstX = vector<bool>(n);
    vstY = vector<bool>(n);
    ll pre = y;
    ll numBetweenInc = 0;
    while (pre != -1) {
        vstX[pre] = true;
        pre = parent[pre];
        numBetweenInc++;
    }
    while (mid != -1) {
        ll budget = k - cost;
        vstX[x] = vstY[y] = true;
        if (budget >= 0) {
            ll val = mxFromMid(mid, budget) + numBetweenInc + 1;
            res = max(res, val);
        }

        cost -= max(distX[mid], distY[mid]);
        cost += distY[mid];
        vstX[mid] = false;
        mid = parent[mid];
        if (mid != -1) {
            cost -= distX[mid];
            cost += max(distX[mid], distY[mid]);
            vstY[mid] = true;
        }
    }

    return res;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, ll, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < w.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 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 103 ms 37832 KB Output is correct
2 Correct 102 ms 42516 KB Output is correct
3 Correct 65 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 432 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 0 ms 344 KB Output is correct
2 Incorrect 0 ms 432 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 0 ms 344 KB Output is correct
2 Incorrect 0 ms 432 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 1 ms 344 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 344 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 344 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 344 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 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -