Skip to content

Commit

Permalink
cf2042B Game with Colored Marbles
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicfred committed Dec 9, 2024
1 parent 9434d87 commit 5de5e6d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions codeforces/cf2042b_game_with_colored_marbles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Vicfred
// https://codeforces.com/contest/2042/problem/B
// greedy
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> c(n);
map<int, int> counter;
for (int i = 0; i < n; ++i) {
cin >> c[i];
counter[c[i]] += 1;
}
vector<int> colors;
for (const auto &[key, value] : counter) {
colors.push_back(value);
}
sort(begin(colors), end(colors));
int answer = 0;
for (int i = 0; i < colors.size(); ++i) {
if (i % 2 == 0 and colors[i] == 1) {
answer += 1;
}
if (i % 2 == 1 and colors[i] == 1) {
answer -= 1;
}
answer += 1;
}
cout << answer << endl;
}
return 0;
}

0 comments on commit 5de5e6d

Please sign in to comment.