結果

問題 No.291 黒い文字列
ユーザー koba-e964koba-e964
提出日時 2021-10-06 11:14:20
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,931 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 159,304 KB
実行使用メモリ 34,008 KB
最終ジャッジ日時 2023-09-30 08:40:28
合計ジャッジ時間 7,322 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 45 ms
5,980 KB
testcase_17 AC 91 ms
10,080 KB
testcase_18 AC 55 ms
6,668 KB
testcase_19 AC 345 ms
17,788 KB
testcase_20 AC 501 ms
19,700 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 669 ms
34,008 KB
testcase_23 AC 1,931 ms
32,524 KB
testcase_24 AC 219 ms
19,228 KB
testcase_25 AC 19 ms
4,380 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}

fn main() {
    let s: Vec<_> = getline().trim().chars().collect();
    let n = s.len();
    let mut hm = HashMap::new();
    hm.insert([0; 4], 0);
    let t = ['K', 'U', 'R', 'O', 'I'];
    for i in 0..n {
        let mut nxt = vec![];
        for j in 0..5 {
            if s[i] != t[j] && s[i] != '?' { continue; }
            for (&k, &v) in &hm {
                if j >= 1 && k[j - 1] == 0 { continue; }
                let mut nxtk = k;
                if j >= 1 {
                    nxtk[j - 1] -= 1;
                }
                let mut nxtv = v;
                if j <= 3 {
                    nxtk[j] += 1;
                } else {
                    nxtv += 1;
                }
                nxt.push((nxtk, nxtv));
            }
        }
        for (k, v) in nxt {
            let ent = hm.entry(k).or_insert(0);
            *ent = max(*ent, v);
        }
    }
    println!("{}", hm.values().max().unwrap());
}
0