QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608152#9349. Exchanging Giftscatwine#WA 408ms3704kbC++141.3kb2024-10-03 19:09:152024-10-03 19:09:15

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 19:09:15]
  • 评测
  • 测评结果:WA
  • 用时:408ms
  • 内存:3704kb
  • [2024-10-03 19:09:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

int n, m, op, x, y, total, mx, res;

void solve() {
  cin >> n;
  vector<vector<int>> a(n + 1);
  vector<unordered_map<int, int>> b(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> op;
    if (op == 1) {
      cin >> m;
      a[i].resize(m);
      for (int j = 0; j < m; j++)
        cin >> a[i][j];
    } else {
      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;
      }
    }

  vector<int> tmp;
  total = res = 0;
  for (const auto &[k, v] : mp) {
    tmp.push_back(v);
    mx = max(v, mx);
    total += v;
  }
  if (mx <= total - mx) {
    res = total;
  } else {
    res = 2 * (total - mx);
  }

  cout << res << endl;
}

signed main() {
  ios_base::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: 0ms
memory: 3640kb

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: 408ms
memory: 3704kb

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'