Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2022 /round3 /fourth_player.cpp
wjomlex's picture
2022 Problems
f7ba5f2 verified
raw
history blame
1.32 kB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int solve() {
int N;
cin >> N;
vector<vector<int>> C(2);
for (int i = 0; i < 4; i++) {
vector<int> H(N/4);
for (int j = 0; j < N/4; j++) {
cin >> H[j];
}
sort(H.begin(), H.end());
if (i == 0) {
C[0] = H;
} else {
int us = i % 2, them = 1 - us;
vector<vector<int>> C2(2);
// Cover as many of their team's highest cards as possible.
for_each(C[them].rbegin(), C[them].rend(), [&](int card) {
if (!H.empty() && H.back() > card) {
C2[us].push_back(H.back());
H.pop_back();
} else {
C2[them].push_back(card);
}
});
// Cover as many of our team's lowest cards as possible.
for (int card : C[us]) {
if (!H.empty() && H.back() >= card) {
C2[us].push_back(H.back());
H.pop_back();
} else {
C2[us].push_back(card);
}
}
C = C2;
sort(C[us].begin(), C[us].end());
sort(C[them].begin(), C[them].end());
}
}
return C[0].size();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
cout << "Case #" << t << ": " << solve() << endl;
}
return 0;
}