結果

問題 No.588 空白と回文
ユーザー phspls
提出日時 2020-05-09 15:47:00
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 27,049 ms
コンパイル使用メモリ 378,324 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 20:17:25
合計ジャッジ時間 12,440 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::max;

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

    let mut result: usize = 1;
    for idx in 0..s.len() {
        let mut width = 1;
        let mut val = 0;
        while idx >= width && idx + width < s.len() {
            if s[idx - width] == s[idx + width] && s[idx - width] != ' ' {
                val += 2;
            }
            width += 1;
        }
        result = max(result, val + 1);
        width = 1;
        val = 0;
        while idx >= width && idx + width - 1 < s.len() {
            if s[idx - width] == s[idx + width - 1] && s[idx - width] != ' ' {
                val += 2;
            }
            width += 1;
        }
        result = max(result, val);
    }
    println!("{}", result);
}
0