QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608155#9349. Exchanging Giftscatwine#WA 402ms3932kbC++141.3kb2024-10-03 19:11:192024-10-03 19:11:19

Judging History

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

  • [2024-10-03 19:11:19]
  • 评测
  • 测评结果:WA
  • 用时:402ms
  • 内存:3932kb
  • [2024-10-03 19:11:19]
  • 提交

answer

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

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

int n, m, 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++) {
    int op;
    cin >> op;
    if (op == 1) {
      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: 0ms
memory: 3588kb

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: 402ms
memory: 3932kb

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'