結果

問題 No.1171 Runs in Subsequences
ユーザー phsplsphspls
提出日時 2023-01-07 03:41:57
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 805 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 145,460 KB
実行使用メモリ 100,620 KB
最終ジャッジ日時 2023-08-20 20:31:14
合計ジャッジ時間 3,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim().chars().map(|c| c as usize - 'a' as usize).collect::<Vec<_>>();

    let n = s.len();
    let mut dp = vec![vec![0usize; 27]; n+1];
    let mut valdp = vec![vec![0usize; 27]; n+1];
    dp[0][26] = 1;
    for i in 0..n {
        for j in 0..=26 {
            if dp[i][j] == 0 { continue; }
            dp[i+1][j] += dp[i][j];
            dp[i+1][s[i]] += dp[i][j];
            dp[i+1][s[i]] %= MOD;

            valdp[i+1][j] += valdp[i][j];
            valdp[i+1][s[i]] += valdp[i][j];
            if s[i] != j {
                valdp[i+1][s[i]] += dp[i][j];
            }
        }
    }
    println!("{}", valdp[n].iter().take(26).sum::<usize>() % MOD);
}
0