結果

問題 No.260 世界のなんとか3
ユーザー ukakukak
提出日時 2017-01-05 07:46:59
言語 Java19
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,053 bytes
コンパイル時間 3,726 ms
コンパイル使用メモリ 74,756 KB
実行使用メモリ 69,484 KB
最終ジャッジ日時 2023-08-22 12:18:28
合計ジャッジ時間 14,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,040 KB
testcase_01 AC 117 ms
55,552 KB
testcase_02 AC 118 ms
55,412 KB
testcase_03 MLE -
testcase_04 MLE -
testcase_05 WA -
testcase_06 WA -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 AC 318 ms
61,948 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 WA -
testcase_14 MLE -
testcase_15 AC 257 ms
59,780 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 WA -
testcase_21 WA -
testcase_22 MLE -
testcase_23 WA -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 AC 120 ms
55,872 KB
testcase_28 MLE -
testcase_29 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String A = in.next();
            String B = in.next();
            int sekaiA = sekai(A.toCharArray(), true);
            int sekaiB = sekai(B.toCharArray(), false);
            System.out.println(sekaiB - sekaiA);
        }
    }

    private static int sekai(char[] N, boolean ignoreAllTight) {
        final int n = N.length;
        // position, tight, mod3, has3, mod8
        final int[][][][][] dp = new int[n + 1][2][3][2][8];
        
        dp[0][1][0][0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 3; k++) {
                    for (int l = 0; l < 2; l++) {
                        for (int m = 0; m < 8; m++) {
                            int lim = j == 1 ? N[i] - '0' : 9;
                            for (int d = 0; d < lim + 1; d++) {
                                int nj = j == 1 && d == lim ? 1 : 0;
                                int nk = (10 * k + d) % 3;
                                int nl = l == 1 || d == 3 ? 1 : 0;
                                int nm = (10 * m + d) % 8;
                                dp[i + 1][nj][nk][nl][nm] += dp[i][j][k][l][m];
                                dp[i + 1][nj][nk][nl][nm] %= MOD;
                            }
                        }
                    }
                }
            }
        }

        int sum = 0;
        for (int j = 0; j < (ignoreAllTight ? 1 : 2); j++) {
            for (int k = 0; k < 3; k++) {
                for (int l = 0; l < 2; l++) {
                    for (int m = 0; m < 8; m++) {
                        if ((k == 0 || l == 1) && m != 0) {
                            sum += dp[n][j][k][l][m];
                            sum %= MOD;
                        }
                    }
                }
            }
        }
        return sum;
    }
}
0