| Task: | Peli |
| Sender: | xnor |
| Submission time: | 2022-01-22 15:42:31 +0200 |
| Language: | Rust |
| Status: | READY |
| Result: | 11 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 11 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | WRONG ANSWER | 0.01 s | 2, 3 | details |
| #3 | WRONG ANSWER | 0.01 s | 3 | details |
| #4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
Code
use std::io::{stdin, BufRead, BufReader};
fn main() {
let mut stdin = BufReader::new(stdin());
let mut cur_line = String::new();
stdin.read_line(&mut cur_line).unwrap();
let mut nums = cur_line
.split_whitespace()
.map(|s| s.parse::<usize>().unwrap());
let n = nums.next().unwrap();
let k = nums.next().unwrap();
cur_line.clear();
stdin.read_line(&mut cur_line).unwrap();
let v = cur_line.as_bytes();
let mut max_a = 0;
let mut max_b = 0;
let mut max_c = 0;
let mut x = 0;
let mut max_abc = 0;
let mut max_ab = 0;
let mut max_bc = 0;
let mut max_ca = 0;
for i in 0..n {
match v[i] {
b'A' => {
max_a += 1;
max_ab += 1;
max_ca += 1;
max_abc += 1;
}
b'B' => {
max_b += 1;
max_ab += 1;
max_bc += 1;
max_abc += 1;
}
b'C' => {
max_c += 1;
max_bc += 1;
max_ca += 1;
max_abc += 1;
}
_ => (),
}
max_abc = max_abc.min(k);
max_ab = max_ab.min(max_abc);
max_bc = max_bc.min(max_abc);
max_ca = max_ca.min(max_abc);
max_a = max_a.min(max_ab).min(max_ca);
max_b = max_b.min(max_ab).min(max_bc);
max_c = max_c.min(max_bc).min(max_ca);
if max_a > 0
&& max_b > 0
&& max_c > 0
&& max_ab > 1
&& max_bc > 1
&& max_ca > 1
&& max_abc > 2
{
x += 1;
max_a -= 1;
max_b -= 1;
max_c -= 1;
max_ab -= 2;
max_bc -= 2;
max_ca -= 2;
max_abc -= 3;
}
max_abc = max_abc.min(k);
max_ab = max_ab.min(max_abc);
max_bc = max_bc.min(max_abc);
max_ca = max_ca.min(max_abc);
max_a = max_a.min(max_ab).min(max_ca);
max_b = max_b.min(max_ab).min(max_bc);
max_c = max_c.min(max_bc).min(max_ca);
}
println!("{}", x);
}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 100000 3 BBAACBCBACBACABBCBAABCBCCBCCAA... |
| correct output |
|---|
| 18201 |
| user output |
|---|
| 18201 |
Test 2
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 10 BAACABCCBCBAACBBCCCCABBBBACCBA... |
| correct output |
|---|
| 29684 |
| user output |
|---|
| 28849 |
Test 3
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 50 ACAABCBBAAAACCBBABACACACBCAACA... |
| correct output |
|---|
| 32740 |
| user output |
|---|
| 32580 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 3 1 ABC |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 3 2 ABC |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
