結果
| 問題 | No.599 回文かい |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-25 02:46:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,708 bytes |
| 記録 | |
| コンパイル時間 | 16,949 ms |
| コンパイル使用メモリ | 400,228 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-27 09:01:53 |
| 合計ジャッジ時間 | 15,423 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 1 |
ソースコード
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;
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 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(unused_macros)]
macro_rules! get {
($t:ty) => {
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.trim().parse::<$t>().unwrap()
}
};
($($t:ty),*) => {
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
$(iter.next().unwrap().parse::<$t>().unwrap(),)*
)
}
};
($t:ty; $n:expr) => {
(0..$n).map(|_|
get!($t)
).collect::<Vec<_>>()
};
($($t:ty),*; $n:expr) => {
(0..$n).map(|_|
get!($($t),*)
).collect::<Vec<_>>()
};
($t:ty ;;) => {
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.split_whitespace()
.map(|t| t.parse::<$t>().unwrap())
.collect::<Vec<_>>()
}
};
}
#[allow(unused_macros)]
macro_rules! debug {
($($a:expr),*) => {
println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
}
}
struct RollingHash {
hash: Vec<u64>,
pow: Vec<u64>,
}
impl RollingHash {
const M: u64 = 1000000007;
const B: u64 = 10009;
fn new(s: &[u64]) -> RollingHash {
let mut hash = Vec::with_capacity(s.len() + 1);
let mut pow = Vec::with_capacity(s.len() + 1);
hash.push(0);
pow.push(1);
for (i, &x) in s.iter().enumerate() {
let h = hash[i];
let p = pow[i];
hash.push((h + x) * Self::B % Self::M);
pow.push(p * Self::B % Self::M);
}
RollingHash {
hash: hash,
pow: pow,
}
}
fn get(&self, l: usize, r: usize) -> u64 {
(self.hash[r] + Self::M - self.hash[l] * self.pow[r - l] % Self::M) % Self::M
}
fn len(&self) -> usize {
self.hash.len() - 1
}
}
const M: usize = 1000000007;
fn rec(rollig_hash: &RollingHash, i: usize, memo: &mut [Option<usize>]) -> usize {
if let Some(res) = memo[i] {
return res;
}
let mut sum = 1;
for k in 1.. {
if i + k > rollig_hash.hash.len() - i - k {
break;
}
if rollig_hash.get(i, i + k) ==
rollig_hash.get(rollig_hash.len() - i - k, rollig_hash.len() - i)
{
sum += rec(rollig_hash, i + k, memo);
sum %= M;
}
}
memo[i] = Some(sum);
sum
}
fn main() {
let s: Vec<u64> = util::line().chars().map(|c| c as u64).collect();
let rolling_hash = RollingHash::new(&s);
let mut memo = vec![None; s.len()];
println!("{}", rec(&rolling_hash, 0, &mut memo));
// debug!(memo);
}