QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571322 | #9349. Exchanging Gifts | ucup-team004# | WA | 154ms | 3680kb | C++20 | 1.7kb | 2024-09-17 22:00:52 | 2024-09-17 22:00:53 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
void solve() {
int n;
std::cin >> n;
std::vector<std::vector<int>> q(n);
std::vector<int> k(n), x(n), y(n), o(n), m(n);
std::vector<i64> len(n), c(n);
for (int i = 0; i < n; i++) {
std::cin >> o[i];
if (o[i] == 1) {
std::cin >> k[i];
q[i].resize(k[i]);
for (int j = 0; j < k[i]; j++) {
std::cin >> q[i][j];
if (m[i] == q[i][j] || c[i] == 0) {
m[i] = q[i][j];
c[i]++;
} else {
c[i]--;
}
}
len[i] = k[i];
} else {
std::cin >> x[i] >> y[i];
x[i]--;
y[i]--;
len[i] = len[x[i]] + len[y[i]];
if (c[x[i]] > c[y[i]]) {
m[i] = m[x[i]];
c[i] = c[x[i]] - c[y[i]];
} else {
m[i] = m[y[i]];
c[i] = c[y[i]] - c[x[i]];
}
}
}
int v = m[n - 1];
for (int i = 0; i < n; i++) {
if (o[i] == 1) {
c[i] = 0;
for (auto x : q[i]) {
c[i] += (x == v);
}
} else {
c[i] = c[x[i]] + c[y[i]];
}
}
i64 ans = std::min(len[n - 1], 2 * (len[n - 1] - c[n - 1]));
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
2 1 1 5 3 3 2 1 3 3 1 3 3 3 2 1 4 2 2 3 3 2 1 2
output:
4 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 154ms
memory: 3680kb
input:
10000 100 1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...
output:
700 68 332 284 131 1048 194 667 754 0 484 252 35 351 1228 238 1025 354 383 571 4272 340 1044 199 448 190 0 69 841 546 247 883 138 1633 91 3308 2556 1280 488 618 407 381 383 2865 0 496 1202 53 0 415 662 380 41 18 91 505 818 603 241 764 1227 1802 176 187 817 1489 460 296 238 236 1028 0 606 1696 746 10...
result:
wrong answer 9th lines differ - expected: '704', found: '754'