結果

問題 No.372 It's automatic
ユーザー tentententen
提出日時 2021-12-03 14:47:55
言語 Java
(openjdk 23)
結果
MLE  
実行時間 -
コード長 1,680 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 77,796 KB
実行使用メモリ 743,684 KB
最終ジャッジ日時 2024-07-05 18:50:27
合計ジャッジ時間 16,926 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 MLE * 12
権限があれば一括ダウンロードができます

ソースコード

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 k = sc.nextInt();
        int length = values.length;
        int[][] dp = new int[length][k];
        int ans = 0;
        for (int i = 0; i < length; i++) {
            int x = values[i] - '0';
            for (int j = 0; j < k && i > 0; j++) {
                if (dp[i - 1][j] > 0) {
                    dp[i][(j * 10 + x) % k] += dp[i - 1][j];
                    dp[i][(j * 10 + x) % k] %= MOD;
                    dp[i][j] += dp[i - 1][j];
                    dp[i][j] %= MOD;
                }
            }
            if (x == 0) {
                ans++;
                ans %= MOD;
            } else {
                dp[i][x % k]++;
            }
        }
        System.out.println((ans + dp[length - 1][0]) % MOD);
    }
}
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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0