QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577952 | #7118. Closing Time | devxxed# | 0 | 89ms | 37556kb | C++20 | 5.7kb | 2024-09-20 15:38:58 | 2024-09-20 15:38:58 |
Judging History
answer
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define fi first
#define se second
#define All(x) x.begin(), x.end()
constexpr ll INF = 1'000'000'000'000'000'000;
template<typename Z> bool chmin(Z &a, Z b) { return ((a > b) ? (a = b, true) : false); }
template<typename Z> bool chmax(Z &a, Z b) { return ((a < b) ? (a = b, true) : false); }
#define debug(x) cout << #x << " = " << (x) << "\n"
template<typename Y, typename Z>
ostream& operator<<(ostream& os, const pair<Y, Z> &p) {
return os << "(" << p.fi << ", " << p.se << ")";
}
template<typename Z>
ostream& operator<<(ostream& os, const vector<Z> &v) {
os << "["; bool _first = true;
for (auto i : v) { if (!_first) { os << ", "; } os << i; _first = false; }
return os << "]";
}
struct Tree {
int n;
vector<vector<int>> adj;
vector<int> u, v;
vector<ll> w;
vector<int> par_edge;
int timer;
vector<int> tin, tout;
vector<bool> special_path;
Tree(int n, vector<int> _u, vector<int> _v, vector<int> _w) :
n(n), adj(n), u(_u), v(_v), w(n-1),
par_edge(n), timer(0), tin(n), tout(n),
special_path(n-1)
{
for (int i = 0; i < n-1; i++) {
adj[u[i]].push_back(i);
adj[v[i]].push_back(i);
w[i] = _w[i];
}
dfsInit(0);
}
void dfsInit(int cur, int prv = -1) {
par_edge[cur] = prv;
tin[cur] = ++timer;
for (auto e : adj[cur]) if (e != prv) {
int nxt = getDest(cur, e);
dfsInit(nxt, e);
}
tout[cur] = timer;
}
int getDest(int x, int e) { return ((x == u[e]) ? v[e] : u[e]); }
bool isAncestor(int anc, int des) {
return tin[anc] <= tin[des] && tout[des] <= tout[anc];
}
pair<vector<int>, vector<ll>> getPath(int x, int y) {
int lca = x;
while (!isAncestor(lca, y)) lca = getDest(lca, par_edge[lca]);
vector<int> nodes_x, nodes_y;
vector<ll> dist_x, dist_y;
while (x != lca) {
special_path[par_edge[x]] = true;
nodes_x.push_back(x);
dist_x.push_back(w[par_edge[x]]);
x = getDest(x, par_edge[x]);
}
while (y != lca) {
special_path[par_edge[y]] = true;
nodes_y.push_back(y);
dist_y.push_back(w[par_edge[y]]);
y = getDest(y, par_edge[y]);
}
nodes_x.push_back(lca);
while (!nodes_y.empty()) { nodes_x.push_back(nodes_y.back()); nodes_y.pop_back(); }
while (!dist_y.empty()) { dist_x.push_back(dist_y.back()); dist_y.pop_back(); }
return {nodes_x, dist_x};
}
void dfsDistance(int x, int prv, ll root_dist, vector<ll> &dist) {
if (root_dist > 0) dist.push_back(root_dist);
for (auto e : adj[x]) {
if (e == prv || special_path[e]) continue;
dfsDistance(getDest(x, e), e, root_dist + w[e], dist);
}
}
vector<ll> getDistances(int x) {
vector<ll> ret;
dfsDistance(x, -1, 0, ret);
return ret;
}
};
vector<vector<ll>> insideTimes(vector<ll> dist, vector<ll> &dx, vector<ll> &dy) {
int n = dist.size() + 1;
dx = dy = vector<ll>(n);
dx[0] = dy[n-1] = 0;
for (int i = 1; i < n; i++) dx[i] = dx[i-1] + dist[i-1];
for (int i = n-2; i >= 0; i--) dy[i] = dy[i+1] + dist[i];
// debug(dx); debug(dy);
vector ret(n+1, vector(n+1, INF));
for (int l = 0; l <= n; l++) {
vector<ll> node_costs(n, 0);
ll sum = 0;
for (int i = 0; i < l; i++) { node_costs[i] = dx[i]; sum += dx[i]; }
for (int r = 0; r <= n; r++) {
if (r > 0) {
int i = n-r;
sum -= node_costs[i];
chmax(node_costs[i], dy[i]);
sum += node_costs[i];
}
ret[l][r] = sum;
}
}
return ret;
}
vector<ll> minPlusConvolution(vector<ll> a, vector<ll> b) {
int n = a.size(), m = b.size();
vector<ll> ret(n + m - 1, INF);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
chmin(ret[i + j], a[i] + b[j]);
}
}
return ret;
}
vector<ll> dncConvolution(int l, int r, vector<vector<ll>> &v) {
if (l == r) return v[l];
int m = (l + r) / 2;
return minPlusConvolution(dncConvolution(l, m, v), dncConvolution(m+1, r, v));
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
Tree T(N, U, V, W);
vector<ll> dx = T.getDistances(X);
vector<ll> dy = T.getDistances(Y);
for (auto y : dy) dx.push_back(y);
sort(All(dy));
int ans = 2;
for (auto y : dy) if (y <= K) { K -= y; ans++; }
return ans;
}
#ifdef Zanite
int main()
{
int Q;
assert(1 == scanf("%d", &Q));
std::vector<int> N(Q), X(Q), Y(Q);
std::vector<long long> K(Q);
std::vector<std::vector<int>> U(Q), V(Q), W(Q);
for (int q = 0; q < Q; q++)
{
assert(4 == scanf("%d %d %d %lld", &N[q], &X[q], &Y[q], &K[q]));
U[q].resize(N[q] - 1);
V[q].resize(N[q] - 1);
W[q].resize(N[q] - 1);
for (int i = 0; i < N[q] - 1; ++i)
{
assert(3 == scanf("%d %d %d", &U[q][i], &V[q][i], &W[q][i]));
}
}
fclose(stdin);
std::vector<int> result(Q);
for (int q = 0; q < Q; q++)
{
result[q] = max_score(N[q], X[q], Y[q], K[q], U[q], V[q], W[q]);
}
for (int q = 0; q < Q; q++)
{
printf("%d\n", result[q]);
}
fclose(stdout);
return 0;
}
#endif
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 89ms
memory: 37556kb
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 320
result:
wrong answer 1st lines differ - on the 1st token, expected: '451', found: '320'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 4084kb
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 51
result:
wrong answer 1st lines differ - on the 1st token, expected: '96', found: '51'
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: 3860kb
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%