結果
問題 | No.588 空白と回文 |
ユーザー | hatoo |
提出日時 | 2017-11-03 22:48:06 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,067 bytes |
コンパイル時間 | 12,797 ms |
コンパイル使用メモリ | 379,032 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 16:09:49 |
合計ジャッジ時間 | 13,886 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{HashMap, HashSet, BinaryHeap}; #[allow(unused_imports)] use std::iter::FromIterator; mod util { use std::io::stdin; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn get<T: FromStr>() -> T where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().parse().unwrap() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn get2<T: FromStr, U: FromStr>() -> (T, U) where <T as FromStr>::Err: Debug, <U as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) } #[allow(dead_code)] pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U) where <S as FromStr>::Err: Debug, <T as FromStr>::Err: Debug, <U as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) } } #[allow(unused_macros)] macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } fn main() { let s: Vec<char> = util::line().chars().collect(); let ans = (0..s.len()) .flat_map(|center| { let len1 = min(center, s.len() - center - 1); let len2 = min(center, s.len() - center); let l1 = &s[center - len1..center]; let l2 = &s[center - len2..center]; let r1 = &s[center + 1..center + 1 + len1]; let r2 = &s[center..center + len2]; vec![ 1 + l1.iter() .rev() .zip(r1.iter()) .filter(|&(&c1, &c2)| c1 == c2) .count() * 2, l2.iter() .rev() .zip(r2.iter()) .filter(|&(&c1, &c2)| c1 == c2) .count() * 2, ].into_iter() }) .max() .unwrap(); println!("{}", ans); }