結果

問題 No.1407 Kindness
ユーザー tentententen
提出日時 2023-01-12 10:47:20
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,815 bytes
コンパイル時間 2,431 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 137,612 KB
最終ジャッジ日時 2023-08-24 19:11:09
合計ジャッジ時間 8,790 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,312 KB
testcase_01 AC 470 ms
70,308 KB
testcase_02 AC 52 ms
51,176 KB
testcase_03 AC 49 ms
48,488 KB
testcase_04 AC 64 ms
51,904 KB
testcase_05 AC 52 ms
51,136 KB
testcase_06 AC 53 ms
51,148 KB
testcase_07 AC 62 ms
52,216 KB
testcase_08 AC 75 ms
51,768 KB
testcase_09 AC 68 ms
52,060 KB
testcase_10 AC 65 ms
52,132 KB
testcase_11 AC 66 ms
51,732 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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 length = inputs.length;
        HashMap<Long, Integer> current = new HashMap<>();
        HashMap<Long, Integer> next = new HashMap<>();
        long base = inputs[0] - '0';
        for (long i = 1; i < base; i++) {
            current.put(i, 1);
        }
        for (int i = 1; i < length; i++) {
            for (long x : current.keySet()) {
                for (int j = 1; j <= 9; j++) {
                    long key = x * j % MOD;
                    next.put(key, (next.getOrDefault(key, 0) + current.get(x)) % MOD);
                }
            }
            for (long j = 1; j < 10; j++) {
                next.put(j, (next.getOrDefault(j, 0) + 1) % MOD);
            }
            if (base > 0) {
                for (int j = 1; j < inputs[i] - '0'; j++) {
                    long key = base * j % MOD;
                    next.put(key, (next.getOrDefault(key, 0) + 1) % MOD);
                }
            }
            base *= inputs[i] - '0';
            base %= MOD;
            HashMap<Long, Integer> tmp = current;
            current = next;
            next = tmp;
            next.clear();
        }
        long ans = base;
        for (long x : current.keySet()) {
            ans += x * current.get(x) % MOD;
            ans %= MOD;
        }
        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