結果

問題 No.291 黒い文字列
ユーザー koba-e964
提出日時 2021-10-06 11:14:20
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1,611 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 12,786 ms
コンパイル使用メモリ 405,852 KB
実行使用メモリ 33,924 KB
最終ジャッジ日時 2024-07-23 02:45:02
合計ジャッジ時間 17,623 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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