CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:ABC-poisto
Sender:PallomerenPiikki
Submission time:2020-10-18 12:03:51 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED42
#2ACCEPTED58
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

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

int solve(string s) {
  int n = s.size();
  vector<int> occ(256);
  for (char c : s) occ[c]++;
  int maxocc = *max_element(occ.begin(), occ.end());
  int others = n - maxocc;
  if (maxocc > others) {
    return maxocc - others;
  }
  return n % 2;
}

signed main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    cout << n-solve(move(s)) << '\n';
  }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
CABC
BABCCBCA
CBBCBBAC
ACAA
...

correct output
4
8
8
2
2
...

user output
4
8
8
2
2
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
100
CCAAACBCBBCCACBBBCCACCCBABBCAB...

correct output
48
4
4
96
70
...

user output
48
4
4
96
70
...
Truncated