結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー phspls
提出日時 2022-09-19 20:29:37
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 13,439 ms
コンパイル使用メモリ 379,776 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-22 02:40:15
合計ジャッジ時間 14,827 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim().chars().collect::<Vec<_>>();

    let mut cnts = vec![vec![0usize; 3]; 3];
    for i in 0..s.len() {
        if s[i] == 'c' {
            cnts[0][i%3] += 1;
        } else if s[i] == 'o' {
            cnts[1][i%3] += 1;
        } else if s[i] == 'n' {
            cnts[2][i%3] += 1;
        }
    }
    let result = (0..3).map(|i| cnts[0][i].min(cnts[1][(i+1)%3]).min(cnts[2][(i+2)%3])).sum::<usize>();
    let result = if result == n && (0..3).map(|i| cnts[i][i] == n).fold(true, |x, y| x && y) {
        n
    } else if result == n {
        n - 1
    } else {
        result
    };
    println!("{}", result);
}
0