# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1038094 | 2024-07-29T12:54:14 Z | Zicrus | 봉쇄 시간 (IOI23_closing) | C++17 | 134 ms | 40548 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) break; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 36808 KB | Output is correct |
2 | Correct | 134 ms | 40548 KB | Output is correct |
3 | Correct | 61 ms | 2908 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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: '19' |
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: '19' |
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: '19' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | 1st lines differ - on the 1st token, expected: '30', found: '19' |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | 1st lines differ - on the 1st token, expected: '30', found: '19' |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | 1st lines differ - on the 1st token, expected: '30', found: '19' |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | 1st lines differ - on the 1st token, expected: '30', found: '19' |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | 1st lines differ - on the 1st token, expected: '30', found: '19' |
4 | Halted | 0 ms | 0 KB | - |