結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー phsplsphspls
提出日時 2022-11-23 00:52:27
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,885 bytes
コンパイル時間 5,840 ms
コンパイル使用メモリ 167,484 KB
実行使用メモリ 19,828 KB
最終ジャッジ日時 2023-10-24 15:15:19
合計ジャッジ時間 4,948 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,372 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 1 ms
4,372 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,372 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,372 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 10 ms
4,372 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 96 ms
19,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    let limit = n.len();
    let mut edp = vec![vec![vec![vec![vec![0usize; 3]; 3]; 2]; 2]; limit];
    let mut ldp = vec![vec![vec![vec![vec![0usize; 3]; 3]; 2]; 2]; limit];
    let cnt2s = vec![0, 0, 1, 0, 2, 0, 1, 0, 2, 0];
    let cnt5s = vec![0, 0, 0, 0, 0, 1, 0, 0, 0, 0];
    edp[n[0]][0][0][cnt2s[n[0]]][cnt5s[n[0]]] = 1;
    for i in 0..n[0] {
        ldp[0][if i==0 { 1 } else { 0 }][0][cnt2s[i]][cnt5s[i]] += 1;
    }
    for i in 0..limit-1 {
        for leading0 in 0..2 {
            for cons0 in 0..2 {
                for cnt2 in 0..3 {
                    for cnt5 in 0..3 {
                        for j in 0..10 {
                            let nleading0 = if leading0 == 1 && j == 0 { 1 } else { 0 };
                            let ncons0 = if cons0 == 1 || (leading0 == 0 && j == 0) { 1 } else { 0 };
                            let ncnt2 = 2.min(cnt2 + cnt2s[j]);
                            let ncnt5 = 2.min(cnt5 + cnt5s[j]);
                            if j == n[i+1] {
                                edp[i+1][nleading0][ncons0][ncnt2][ncnt5] += edp[i][leading0][cons0][cnt2][cnt5];
                            } else if j < n[i+1] {
                                ldp[i+1][nleading0][ncons0][ncnt2][ncnt5] += edp[i][leading0][cons0][cnt2][cnt5];
                            }
                            ldp[i+1][nleading0][ncons0][ncnt2][ncnt5] += ldp[i][leading0][cons0][cnt2][cnt5];
                            ldp[i+1][nleading0][ncons0][ncnt2][ncnt5] %= MOD;
                        }
                    }
                }
            }
        }
    }
    println!("{}", (edp[limit-1][0][0][2][2] + ldp[limit-1][0][0][2][2]) % MOD);
}
0