結果

問題 No.599 回文かい
ユーザー phsplsphspls
提出日時 2023-01-14 00:44:44
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,235 bytes
コンパイル時間 3,139 ms
コンパイル使用メモリ 136,024 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 05:45:42
合計ジャッジ時間 10,056 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: usize = 1e9 as usize + 7;

fn zalgorithm(s: &str) -> Vec<usize> {
    let n = s.len();
    let svec = s.chars().collect::<Vec<_>>();
    let mut ret = vec![0usize; n];
    ret[0] = n;
    let mut i = 1usize;
    let mut j = 0usize;
    while i < n {
        while i+j < n && svec[j] == svec[i+j] {
            j += 1;
        }
        ret[i] = j;

        if j == 0 {
            i += 1;
            continue;
        }
        let mut k = 1usize;
        while k < j && k + ret[k] < j {
            ret[i+k] = ret[k];
            k += 1;
        }
        i += k;
        j -= k;
    }
    ret
}

fn dfs(idx: usize, dists: &Vec<Vec<usize>>) -> usize {
    if idx * 2 == dists[0].len() {
        return 1usize;
    }
    let n = dists[0].len() - 2*idx;
    let mut ret = 1usize;
    for size in 1..=n/2 {
        if dists[idx][n-size] == size {
            ret += dfs(idx+size, dists);
            ret %= MOD;
        }
    }
    ret
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim();

    let mut dists = Vec::with_capacity(s.len()/2+1);
    for i in 0..s.len()/2 {
        dists.push(zalgorithm(&s[i..s.len()-i]));
    }
    println!("{}", dfs(0, &dists));
}
0