| Task: | Peli |
| Sender: | xnor |
| Submission time: | 2022-01-22 16:57:35 +0200 |
| Language: | Rust |
| Status: | READY |
| Result: | 42 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 11 |
| #2 | ACCEPTED | 31 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.11 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.25 s | 2, 3 | details |
| #3 | RUNTIME ERROR | 0.10 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.trim().as_bytes();
let mut dp = vec![[[[0u16; 10]; 10]; 10]; n];
for a in 0..k {
for b in 0..k {
for c in 0..k {
if a + b + c < k {
match v.last().unwrap() {
b'A' => {
if a == 0 && b > 0 && c > 0 {
dp[v.len() - 1][a][b][c] = 1;
}
}
b'B' => {
if a > 0 && b == 0 && c > 0 {
dp[v.len() - 1][a][b][c] = 1;
}
}
b'C' => {
if a > 0 && b > 0 && c == 0 {
dp[v.len() - 1][a][b][c] = 1;
}
}
_ => (),
}
}
}
}
}
for i in (0..n - 1).rev() {
for a in 0..k {
for b in 0..k {
if a + b >= k {
break;
}
for c in 0..k {
if a + b + c >= k {
break;
}
match v[i] {
b'A' => {
if a == 0 && b > 0 && c > 0 {
dp[i][a][b][c] = 1 + dp[i + 1][a][b - 1][c - 1];
} else if a < k - 1 {
dp[i][a][b][c] = dp[i + 1][a + 1][b][c].max(dp[i + 1][a][b][c]);
}
}
b'B' => {
if a > 0 && b == 0 && c > 0 {
dp[i][a][b][c] = 1 + dp[i + 1][a - 1][b][c - 1];
} else if b < k - 1 {
dp[i][a][b][c] = dp[i + 1][a][b + 1][c].max(dp[i + 1][a][b][c]);
}
}
b'C' => {
if a > 0 && b > 0 && c == 0 {
dp[i][a][b][c] = 1 + dp[i + 1][a - 1][b - 1][c];
} else if c < k - 1 {
dp[i][a][b][c] = dp[i + 1][a][b][c + 1].max(dp[i + 1][a][b][c]);
}
}
_ => (),
}
}
}
}
}
println!("{}", dp[0][0][0][0]);
}
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: ACCEPTED
| input |
|---|
| 100000 10 BAACABCCBCBAACBBCCCCABBBBACCBA... |
| correct output |
|---|
| 29684 |
| user output |
|---|
| 29684 |
Test 3
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 50 ACAABCBBAAAACCBBABACACACBCAACA... |
| correct output |
|---|
| 32740 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 10 but the index is 10', input/...
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 |
