結果

問題 No.372 It's automatic
ユーザー tentententen
提出日時 2023-06-13 16:59:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,137 ms / 6,000 ms
コード長 2,277 bytes
コンパイル時間 4,309 ms
コンパイル使用メモリ 86,580 KB
実行使用メモリ 53,272 KB
最終ジャッジ日時 2023-09-04 02:32:21
合計ジャッジ時間 32,423 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,304 KB
testcase_01 AC 46 ms
49,912 KB
testcase_02 AC 46 ms
49,388 KB
testcase_03 AC 46 ms
49,388 KB
testcase_04 AC 2,072 ms
52,700 KB
testcase_05 AC 1,990 ms
52,852 KB
testcase_06 AC 2,014 ms
52,924 KB
testcase_07 AC 2,057 ms
52,832 KB
testcase_08 AC 2,043 ms
52,872 KB
testcase_09 AC 2,137 ms
52,744 KB
testcase_10 AC 1,971 ms
53,028 KB
testcase_11 AC 1,995 ms
52,880 KB
testcase_12 AC 2,025 ms
52,968 KB
testcase_13 AC 2,002 ms
53,052 KB
testcase_14 AC 2,098 ms
53,120 KB
testcase_15 AC 2,036 ms
52,956 KB
testcase_16 AC 48 ms
49,324 KB
testcase_17 AC 47 ms
49,332 KB
testcase_18 AC 48 ms
49,320 KB
testcase_19 AC 48 ms
49,348 KB
testcase_20 AC 46 ms
49,784 KB
testcase_21 AC 206 ms
53,272 KB
testcase_22 AC 228 ms
53,012 KB
testcase_23 AC 211 ms
52,848 KB
testcase_24 AC 209 ms
52,828 KB
testcase_25 AC 216 ms
52,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        int m = sc.nextInt();
        int[] current = new int[m];
        int[] next = new int[m];
        int ans = 0;
        for (char c : inputs) {
            int x = c - '0';
            for (int i = 0; i < m; i++) {
                next[(i * 10 + x) % m] += current[i];
                next[(i * 10 + x) % m] %= MOD;
            }
            if (x > 0) {
                next[x % m]++;
                next[x % m] %= MOD;
            } else {
                ans++;
                ans %= MOD;
            }
            ans += next[0];
            ans %= MOD;
            for (int i = 0; i < m; i++) {
                current[i] += next[i];
                current[i] %= MOD;
            }
            Arrays.fill(next, 0);
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0