QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291925 | #7118. Closing Time | danielkou5855 | 0 | 91ms | 35856kb | C++17 | 3.0kb | 2023-12-27 13:47:45 | 2024-04-28 08:00:33 |
Judging History
answer
// Source: https://usaco.guide/general/io
#include "closing.h"
#include <bits/stdc++.h>
// #define int long long
#define double long double
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define edge pair<int, int>
using namespace std;
vector<vector<edge>> adj;
vector<int> psum1, psum2;
int NO1, NO2;
void genshit(int c, int p, int flag) {
if (p != -1 && flag == 0 && c == NO1) {
return;
}
if (p != -1 && flag == 1 && c == NO2) {
return;
}
for (auto n : adj[c]) {
if (n.first != p) {
if (flag == 0) {
psum1[n.first] = psum1[c] + n.second;
} else {
psum2[n.first] = psum2[c] + n.second;
}
genshit(n.first, c, flag);
}
}
}
struct cmp {
bool operator()(const array<int, 3> &x, const array<int, 3> &y) const {
return x[0] > y[0];
}
};
struct cmp2 {
bool operator()(const array<int, 3> &x, const array<int, 3> &y) const {
return x[0] < y[0];
}
};
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
adj.resize(N); psum1.resize(N); psum2.resize(N); NO1 = X, NO2 = Y;
for (int i = 0; i < N; i++) {
adj[i].clear(); psum1[i] = psum2[i] = 0;
}
for (int i = 0; i < N - 1; i++) {
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
}
// gen psum
genshit(X, -1, 0); genshit(Y, -1, 1);
// do the cardboard box thing
vector<int> a(N), b(N);
for (int i = 0; i < N; i++) {
a[i] = min(psum1[i], psum2[i]);
b[i] = max(psum1[i], psum2[i]);
// cout << psum1[i] << " " << psum2[i] << "\n";
// cout << a[i] << " " << b[i] << "\n";
}
vector<int> status(N, 0); // 0 = nothing, 1 = one only, 2 = both
// {cost, vertex, index}
priority_queue<array<int, 3>, vector<array<int, 3>>, cmp> pq;
vector<array<int, 3>> trust;
for (int i = 0; i < N; i++) {
trust.push_back({a[i], i, 0});
}
int ans = 0; int ct = 0;
sort(all(trust), cmp2());
int maxwt = 0;
while (ans <= K) {
if (ct == N) {
return ct;
}
if (ans + trust[ct][0] <= K) {
// cout << trust[ct][1] << "\n";
ans += trust[ct][0]; status[trust[ct][1]]++;
pq.push({b[trust[ct][1]] - a[trust[ct][1]], trust[ct][1], 1}); ct++; maxwt = max(maxwt, trust[ct][0]);
} else {
break;
}
}
// cout << ans << "\n";
while (!pq.empty()) {
auto t = pq.top(); pq.pop();
bool fin = true;
if (ans + t[0] <= K) {
// check if all adj are activated
// for (auto n : adj[t[1]]) {
// if (!status[n.first]) {
// fin = false;
// }
// }
if (t[0] + a[t[1]] < maxwt) {
// cout << t[0] << "\n";
ans += t[0]; status[t[1]]++; ct++;
}
}
}
return ct;
}
// signed main() {
// cin.tie(0) -> sync_with_stdio(false);
// int T; cin >> T;
// while (T--) {
// int N, X, Y, K; cin >> N >> X >> Y >> K;
// vector<int> U(N - 1), V(N - 1), W(N - 1);
// for (int i = 0; i < N - 1; i++) {
// cin >> U[i] >> V[i] >> W[i];
// }
// cout << max_score(N, X, Y, K, U, V, W) << "\n";
// }
// }
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 91ms
memory: 35856kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 200000 31011 61157 8517583098 31011 129396 964383 1655 129396 331139 1655 191487 566483 110385 191487 865248 43212 110385 542661 43212 81682 13766 81682 91774 546589 91774 124706 780638 124706 175650 118706 10421 175650 615314 10421 151953 436270 140430 151...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 200000
result:
wrong answer 1st lines differ - on the 1st token, expected: '451', found: '200000'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3812kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 23 25 382806473 0 1 375710 1 2 898637 2 3 10402 3 4 536577 4 5 385023 5 6 71075 6 7 543368 7 8 301497 8 9 174394 9 10 711312 10 11 923006 11 12 675532 12 13 838667 13 14 565729 14 15 979816 15 16 862618 16 17 576015 17 18 177751 18 19 306989 19 20 881492...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 50
result:
wrong answer 1st lines differ - on the 1st token, expected: '96', found: '50'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 0ms
memory: 3804kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 9 0 2 2 1 2 3 2 3 3
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 4
result:
wrong answer 1st lines differ - on the 1st token, expected: '6', found: '4'
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #4:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%