結果

問題 No.260 世界のなんとか3
ユーザー ぴろずぴろず
提出日時 2015-08-01 00:06:33
言語 Java19
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,479 bytes
コンパイル時間 4,029 ms
コンパイル使用メモリ 73,720 KB
実行使用メモリ 70,972 KB
最終ジャッジ日時 2023-08-07 13:58:08
合計ジャッジ時間 13,384 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,552 KB
testcase_01 AC 120 ms
55,992 KB
testcase_02 AC 117 ms
55,852 KB
testcase_03 MLE -
testcase_04 MLE -
testcase_05 AC 228 ms
59,244 KB
testcase_06 AC 209 ms
59,536 KB
testcase_07 MLE -
testcase_08 AC 303 ms
63,404 KB
testcase_09 AC 269 ms
59,808 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 AC 335 ms
62,404 KB
testcase_13 AC 224 ms
59,360 KB
testcase_14 MLE -
testcase_15 AC 223 ms
59,664 KB
testcase_16 AC 384 ms
63,008 KB
testcase_17 MLE -
testcase_18 MLE -
testcase_19 AC 361 ms
63,480 KB
testcase_20 AC 285 ms
61,892 KB
testcase_21 AC 300 ms
62,648 KB
testcase_22 AC 416 ms
63,648 KB
testcase_23 AC 183 ms
55,044 KB
testcase_24 AC 358 ms
63,272 KB
testcase_25 MLE -
testcase_26 MLE -
testcase_27 AC 115 ms
55,716 KB
testcase_28 MLE -
testcase_29 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no260b;

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static long MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		long bb = aho(b);
		long aa = aho(new BigInteger(a).subtract(BigInteger.ONE).toString());
		System.out.println((bb + MOD - aa) % MOD);
	}
	public static long aho(String ss) {
		char[] s = ss.toCharArray();
		int n = s.length;
		long[][][][] dp = new long[2][2][24][n+1];
		dp[0][0][0][0] = 1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<24;j++) {
				for(int k=0;k<2;k++) {
					LOOP: for(int l=0;l<2;l++) {
						for(int m=0;m<=9;m++) {
							int l2;
							if (l == 0) {
								if (m + '0' == s[i]) {
									l2 = 0;
								}else if(m + '0' < s[i]) {
									l2 = 1;
								}else{
									continue LOOP;
								}
							}else{
								l2 = 1;
							}
							int k2 = (k == 1 || m == 3) ? 1 : 0;
							int j2 = (j * 10 + m) % 24;
							dp[l2][k2][j2][i+1] += dp[l][k][j][i];
						}
					}
				}
			}
			for(int j=0;j<24;j++) {
				for(int k=0;k<2;k++) {
					for(int l=0;l<2;l++) {
						dp[l][k][j][i+1] %= MOD;
					}
				}
			}
		}
		long ret = 0;
		for(int i=0;i<2;i++) {
			for(int j=0;j<2;j++) {
				for(int k=0;k<24;k++) {
					if ((j == 1 || (k % 3 == 0)) && (k % 8 != 0)) {
						ret += dp[i][j][k][n];
						if (ret >= MOD) {
							ret -= MOD;
						}
					}
				}
			}
		}
		return ret;
	}
}
0