CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:ABC-poisto
Sender:TapaniS
Submission time:2020-10-16 20:59:49 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED42
#2ACCEPTED58
Test results
testverdicttimegroup
#1ACCEPTED0.17 s1, 2details
#2ACCEPTED0.21 s2details

Code

import java.util.*;
public class abc {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//int t = input.nextInt();
int t = Integer.parseInt(input.nextLine());
int aqty = 0;
int bqty = 0;
int cqty = 0;
int maxqty = 0;
int minqty = 0;
int rest = 0;
int ans = 0;
for (int i = 0; i < t; i++) {
String abc = input.nextLine();
int lngt = abc.length();
String a = abc.replaceAll("B","");
a = a.replaceAll("C","");
aqty = a.length();
String b = abc.replaceAll("A","");
b = b.replaceAll("C","");
bqty = b.length();
maxqty = Math.max(aqty, bqty);
minqty = Math.min(aqty, bqty);
cqty = lngt - aqty - bqty;
maxqty = Math.max(maxqty, cqty);
minqty = Math.min(minqty, cqty);
rest = lngt - maxqty - minqty;
if ((rest + minqty) >= maxqty) ans = lngt - (lngt % 2);
else ans = (rest + minqty) * 2;
System.out.println(ans);
}
input.close();
}
}

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