結果
問題 | No.260 世界のなんとか3 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-21 10:16:12 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,621 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 121,216 KB |
実行使用メモリ | 17,664 KB |
最終ジャッジ日時 | 2024-06-13 03:28:15 |
合計ジャッジ時間 | 4,763 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
15,744 KB |
testcase_01 | AC | 73 ms
15,744 KB |
testcase_02 | AC | 71 ms
15,744 KB |
testcase_03 | AC | 111 ms
17,540 KB |
testcase_04 | AC | 119 ms
17,664 KB |
testcase_05 | AC | 90 ms
16,384 KB |
testcase_06 | AC | 82 ms
16,256 KB |
testcase_07 | AC | 110 ms
17,280 KB |
testcase_08 | AC | 116 ms
17,280 KB |
testcase_09 | AC | 95 ms
16,512 KB |
testcase_10 | AC | 107 ms
17,100 KB |
testcase_11 | AC | 113 ms
17,408 KB |
testcase_12 | AC | 110 ms
17,020 KB |
testcase_13 | AC | 75 ms
16,000 KB |
testcase_14 | AC | 113 ms
17,280 KB |
testcase_15 | AC | 81 ms
16,096 KB |
testcase_16 | AC | 100 ms
16,964 KB |
testcase_17 | AC | 96 ms
16,640 KB |
testcase_18 | AC | 94 ms
16,640 KB |
testcase_19 | AC | 119 ms
17,280 KB |
testcase_20 | AC | 98 ms
16,768 KB |
testcase_21 | AC | 103 ms
16,768 KB |
testcase_22 | AC | 100 ms
17,152 KB |
testcase_23 | AC | 72 ms
15,872 KB |
testcase_24 | AC | 115 ms
17,152 KB |
testcase_25 | AC | 140 ms
17,536 KB |
testcase_26 | AC | 109 ms
17,536 KB |
testcase_27 | AC | 71 ms
15,744 KB |
testcase_28 | AC | 73 ms
17,664 KB |
testcase_29 | WA | - |
ソースコード
import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } void chmin(T)(ref T t, in T f) { if (t > f) t = f; } void chmax(T)(ref T t, in T f) { if (t < f) t = f; } int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } enum MO = 10L^^9 + 7; enum M = 24; enum LIM = 10^^4 + 10; long[] ten; long[][][] dp; int N; string A, B; long calc(int i, int x, int y, bool diffA, bool diffB) { long ret; if (i == N) { ret += ((x % 3 == 0 || y) && (x % 8 != 0)) ? 1 : 0; } else if (diffA && diffB) { foreach (dx; 0 .. M) foreach (dy; 0 .. 2) { const xx = (x * ten[N - i] + dx) % M; const yy = y | dy; if ((xx % 3 == 0 || yy) && (xx % 8 != 0)) { ret += dp[N - i][dx][dy]; } } } else { foreach (d; (diffA ? 0 : (A[i] - '0')) .. (diffB ? 9 : (B[i] - '0')) + 1) { ret += calc(i + 1, x * 10 + d, (y || d == 3) ? 1 : 0, (diffA || (d != A[i] - '0')), (diffB || (d != B[i] - '0'))); } } ret %= MO; debug { writefln("calc %s %s %s %s %s: %s", i, x, y, diffA, diffB, ret); } return ret; } void main() { ten = new long[LIM]; ten[0] = 1; foreach (i; 1 .. LIM) { ten[i] = (ten[i - 1] * 10) % M; } dp = new long[][][](LIM + 1, M, 2); dp[0][0][0] = 1; foreach (i; 0 .. LIM) { foreach (x; 0 .. M) foreach (y; 0 .. 2) { foreach (d; 0 .. 10) { (dp[i + 1][(x * 10 + d) % M][(y || d == 3) ? 1 : 0] += dp[i][x][y]) %= MO; } } } try { for (; ; ) { A = readToken(); B = readToken(); N = cast(int)(B.length); A = iota(N - A.length).map!(_ => '0').array.to!string ~ A; debug { writeln("A = ", A); writeln("B = ", B); } const ans = calc(0, 0, 0, false, false); writeln(ans); } } catch (EOFException e) { } }