QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630154 | #9349. Exchanging Gifts | crimsonsunset# | WA | 286ms | 3612kb | C++20 | 1.4kb | 2024-10-11 16:46:22 | 2024-10-11 16:46:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const long long mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> ct(n);
ct[n - 1] = 1;
vector<vector<int>> a(n);
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
if (t == 2) {
a[i].push_back(-1);
int lol, kek;
cin >> lol >> kek;
a[i].push_back(lol);
a[i].push_back(kek);
}
else {
int nn;
cin >> nn;
for (int j = 0; j < nn; ++j) {
int x;
cin >> x;
a[i].push_back(x);
}
}
}
map<int, int> ctt;
for (int i = n - 1; i >= 0; --i) {
if (a[i][0] == -1) {
ct[a[i][1] - 1] += ct[i];
ct[a[i][2] - 1] += ct[i];
}
else {
for (auto e : a[i]) ctt[e] += ct[i];
}
}
int S = 0;
// cout << S << endl;
for (auto e : ctt) S += e.second;
int ans = 0;
for (auto e : ctt) ans = max(ans, e.second - S / 2);
cout << S - (ans * 2) + S % 2 << '\n';
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 286ms
memory: 3612kb
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 132 1048 194 668 704 0 484 252 36 352 1228 238 1026 354 384 572 4272 340 1044 200 448 190 0 70 842 546 248 884 138 1634 92 3308 2556 1280 488 618 408 382 384 2866 0 496 1202 54 0 416 662 380 42 18 92 506 818 604 242 764 1228 1802 176 188 818 1490 460 296 238 236 1028 0 606 1696 746 10...
result:
wrong answer 5th lines differ - expected: '131', found: '132'