Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 1,117 Bytes
d3f4f72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <map>
#include <utility>
using namespace std;

int N, M;

int solve() {
  map<int, pair<int, int>> curr, next;
  cin >> N >> M;
  for (int i = 0, s; i < M; i++) {
    cin >> s;
    int v = curr[s].first + 1;
    curr[s] = make_pair(v, v);
  }
  int ans = 0;
  for (int i = 0, p; i < N; i++) {
    map<int, int> req;
    for (int j = 0; j < M; j++) {
      cin >> p;
      req[p]++;
    }
    next.clear();
    for (auto [k, v] : curr) {
      auto it = req.find(k);
      int num_to_change = max(0, v.first - (it != req.end() ? it->second : 0));
      int num_to_change_for_free = min(num_to_change, v.second);
      ans += num_to_change - num_to_change_for_free;
      curr[k].second -= num_to_change_for_free;
    }
    for (auto [k, v] : req) {
      auto it = curr.find(k);
      next[k] = make_pair(v, min(v, it != curr.end() ? it->second.second : 0));
    }
    curr = next;
  }
  return ans;
}

int main() {
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    cout << "Case #" << t << ": " << solve() << endl;
  }
  return 0;
}