結果

問題 No.372 It's automatic
ユーザー tentententen
提出日時 2021-12-03 15:52:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,429 ms / 6,000 ms
コード長 1,788 bytes
コンパイル時間 2,857 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 52,816 KB
最終ジャッジ日時 2023-09-19 07:43:39
合計ジャッジ時間 33,624 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,420 KB
testcase_01 AC 44 ms
49,408 KB
testcase_02 AC 45 ms
49,388 KB
testcase_03 AC 44 ms
47,288 KB
testcase_04 AC 2,344 ms
52,388 KB
testcase_05 AC 2,429 ms
52,312 KB
testcase_06 AC 2,327 ms
52,516 KB
testcase_07 AC 2,273 ms
52,812 KB
testcase_08 AC 2,350 ms
52,184 KB
testcase_09 AC 2,015 ms
52,816 KB
testcase_10 AC 2,273 ms
52,564 KB
testcase_11 AC 2,251 ms
52,380 KB
testcase_12 AC 2,353 ms
52,560 KB
testcase_13 AC 2,254 ms
52,464 KB
testcase_14 AC 2,274 ms
52,532 KB
testcase_15 AC 2,288 ms
52,552 KB
testcase_16 AC 47 ms
49,316 KB
testcase_17 AC 47 ms
49,492 KB
testcase_18 AC 47 ms
49,300 KB
testcase_19 AC 46 ms
49,184 KB
testcase_20 AC 46 ms
49,228 KB
testcase_21 AC 182 ms
52,796 KB
testcase_22 AC 197 ms
52,432 KB
testcase_23 AC 185 ms
52,804 KB
testcase_24 AC 186 ms
52,496 KB
testcase_25 AC 186 ms
52,592 KB
権限があれば一括ダウンロードができます

ソースコード

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[] prev = new int[k];
        int[] next = new int[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 (prev[j] > 0) {
                    next[(j * 10 + x) % k] += prev[j];
                    next[(j * 10 + x) % k] %= MOD;
                    next[j] += prev[j];
                    next[j] %= MOD;
                }
            }
            if (x == 0) {
                ans++;
                ans %= MOD;
            } else {
                next[x % k]++;
            }
            int[] tmp = prev;
            prev = next;
            next = tmp;
            Arrays.fill(next, 0);
        }
        System.out.println((ans + prev[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