結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー tenten
提出日時 2022-08-17 14:18:38
言語 Java
(openjdk 23)
結果
AC  
実行時間 171 ms / 3,000 ms
コード長 2,175 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 77,308 KB
実行使用メモリ 48,732 KB
最終ジャッジ日時 2024-10-04 15:43:40
合計ジャッジ時間 6,405 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] values = sc.next().toCharArray();
        int length = values.length;
        int[][] dp = new int[length + 1][100];
        int current = values[0] - '0';
        boolean isZero = false;
        for (int i = 1; i < values[0] - '0'; i++) {
            dp[1][i]++;
        }
        for (int i = 1; i < length; i++) {
            int v = values[i] - '0';
            for (int j = 0; j < 100; j++) {
                if (dp[i][j] == 0) {
                    continue;
                }
                for (int k = 1; k <= 9; k++) {
                    dp[i + 1][j * k % 100] += dp[i][j];
                    dp[i + 1][j * k % 100] %= MOD;
                }
            }
            if (!isZero) {
                for (int j = 1; j < v; j++) {
                    dp[i + 1][current * j % 100]++;
                    dp[i + 1][current * j % 100] %= MOD;
                }
                isZero = (v == 0);
                current *= v;
                current %= 100;
            }
            for (int j = 1; j <= 9; j++) {
                dp[i + 1][j]++;
                dp[i + 1][j] %= MOD;
            }
        }
        if (!isZero) {
            dp[length][current]++;
            dp[length][current] %= MOD;
        }
        System.out.println(dp[length][0]);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0