結果

問題 No.273 回文分解
ユーザー sino
提出日時 2020-04-18 21:25:45
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,425 bytes
コンパイル時間 13,927 ms
コンパイル使用メモリ 377,804 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-04 00:21:38
合計ジャッジ時間 13,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let s = read!(String);
    let s: Vec<char> = s.chars().collect();

    let mut max = (1, 1);
    for start in 0..s.len() {
        for end in start+max.1+1..s.len()+1 {
            if is_palindrome(&s[start..end]) {
                max = (max.1, end - start);
            }
        }
    }
    if max.1 != s.len() {
        println!("{}", max.1);
    }
    else {
        println!("{}", max.0);
    }
}


fn is_palindrome(s: &[char]) -> bool {
    let mut flg = true;
    let len = s.len();
    for i in 0..len/2 {
        flg &= s[i] == s[len-1 - i];
    }
    flg
}
0