結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー phsplsphspls
提出日時 2022-11-09 23:52:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 120 ms / 3,000 ms
コード長 1,933 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 151,740 KB
実行使用メモリ 19,844 KB
最終ジャッジ日時 2023-09-30 10:34:55
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 10 ms
4,380 KB
testcase_32 AC 21 ms
5,600 KB
testcase_33 AC 55 ms
10,852 KB
testcase_34 AC 109 ms
19,576 KB
testcase_35 AC 113 ms
19,844 KB
testcase_36 AC 109 ms
19,844 KB
testcase_37 AC 120 ms
19,836 KB
testcase_38 AC 101 ms
19,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `SIZE` should have a snake case name
 --> Main.rs:9:9
  |
9 |     let SIZE = n.len();
  |         ^^^^ help: convert the identifier to snake case: `size`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: 1 warning emitted

ソースコード

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 SIZE = n.len();
    let map0 = vec![1,0,0,0,0,0,0,0,0,0];
    let map2 = vec![0,0,1,0,2,0,1,0,2,0];
    let map5 = vec![0,0,0,0,0,1,0,0,0,0];
    // n -> leading0 -> 0 included -> 2 times -> 5 times
    let mut edp = vec![vec![vec![vec![vec![0usize; 3]; 3]; 2]; 2]; SIZE];
    let mut ldp = vec![vec![vec![vec![vec![0usize; 3]; 3]; 2]; 2]; SIZE];
    edp[0][0][0][map2[n[0]]][map5[n[0]]] = 1;
    for i in 0..n[0] {
        ldp[0][map0[i]][0][map2[i]][map5[i]] += 1;
    }
    for i in 1..SIZE {
        for leading0 in 0..2 {
            for inc0 in 0..2 {
                for time2 in 0..3 {
                    for time5 in 0..3 {
                        for j in 0..10 {
                            let nleading0 = if leading0 == 1 && j == 0 { 1 } else { 0 };
                            let ninc0 = if leading0 == 1 || (inc0 == 0 && j > 0) { 0 } else { 1 };
                            let ntime2 = (time2+map2[j]).min(2);
                            let ntime5 = (time5+map5[j]).min(2);
                            if j == n[i] {
                                edp[i][nleading0][ninc0][ntime2][ntime5] += edp[i-1][leading0][inc0][time2][time5];
                            } else if j < n[i] {
                                ldp[i][nleading0][ninc0][ntime2][ntime5] += edp[i-1][leading0][inc0][time2][time5];
                            }
                            ldp[i][nleading0][ninc0][ntime2][ntime5] += ldp[i-1][leading0][inc0][time2][time5];
                            ldp[i][nleading0][ninc0][ntime2][ntime5] %= MOD;
                        }
                    }
                }
            }
        }
    }
    println!("{}", (edp[SIZE-1][0][0][2][2] + ldp[SIZE-1][0][0][2][2]) % MOD);
}
0