QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#608162 | #9349. Exchanging Gifts | catwine# | WA | 1ms | 3564kb | C++14 | 1.3kb | 2024-10-03 19:15:06 | 2024-10-03 19:15:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
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;
}
}
int mx, total = 0, 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();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3564kb
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:
-8589934580 -8589934576
result:
wrong answer 1st lines differ - expected: '4', found: '-8589934580'