QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608157 | #9349. Exchanging Gifts | catwine# | WA | 411ms | 3912kb | C++14 | 1.3kb | 2024-10-03 19:12:03 | 2024-10-03 19:12:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int total, mx, res;
void solve() {
int n;
cin >> n;
vector<vector<int>> a(n + 1);
vector<unordered_map<int, int>> b(n + 1);
for (int i = 1; i <= n; i++) {
int op;
cin >> op;
if (op == 1) {
int m;
cin >> m;
a[i].resize(m);
for (int j = 0; j < m; j++)
cin >> a[i][j];
} else {
int x, y;
cin >> x >> y;
if (b[x].size())
for (auto [num, cnt] : b[x])
b[i][num] += cnt;
else
b[i][x]++;
if (b[y].size())
for (auto [num, cnt] : b[y])
b[i][num] += cnt;
else
b[i][y]++;
}
}
unordered_map<int, int> mp;
if (a[n].size())
for (auto x : a[n])
mp[x]++;
else
for (auto [num, cnt] : b[n]) {
for (auto x : a[num]) {
mp[x] += cnt;
}
}
total = res = 0;
for (const auto &[k, v] : mp) {
mx = max(v, mx);
total += v;
}
if (mx <= total - mx) {
res = total;
} else {
res = 2 * (total - mx);
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
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: 411ms
memory: 3912kb
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 -104 332 284 -76 1048 -182 667 704 0 -216 -776 -1210 -578 1176 -804 770 -572 -514 -138 4272 -2204 -796 -2486 -1988 -2504 0 -2780 -1236 -1826 -2424 -1152 -2642 348 -2736 3308 2194 -358 -1942 -1682 -2104 -2156 -2152 2812 -104 -1926 -514 -2812 -2610 -2088 -1594 -2158 -2836 -2882 -2736 -1908 -1282 -...
result:
wrong answer 2nd lines differ - expected: '68', found: '-104'