結果

問題 No.260 世界のなんとか3
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-21 10:16:12
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,621 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 108,820 KB
実行使用メモリ 18,752 KB
最終ジャッジ日時 2023-09-03 22:50:39
合計ジャッジ時間 4,888 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
15,960 KB
testcase_01 AC 71 ms
17,160 KB
testcase_02 AC 75 ms
16,052 KB
testcase_03 AC 118 ms
17,804 KB
testcase_04 AC 118 ms
17,804 KB
testcase_05 AC 94 ms
16,752 KB
testcase_06 AC 87 ms
17,408 KB
testcase_07 AC 115 ms
18,392 KB
testcase_08 AC 123 ms
18,752 KB
testcase_09 AC 98 ms
16,688 KB
testcase_10 AC 107 ms
18,192 KB
testcase_11 AC 118 ms
17,572 KB
testcase_12 AC 111 ms
18,192 KB
testcase_13 AC 80 ms
17,664 KB
testcase_14 AC 116 ms
18,460 KB
testcase_15 AC 82 ms
16,580 KB
testcase_16 AC 107 ms
18,464 KB
testcase_17 AC 99 ms
17,000 KB
testcase_18 AC 94 ms
16,748 KB
testcase_19 AC 118 ms
17,576 KB
testcase_20 AC 100 ms
17,040 KB
testcase_21 AC 106 ms
18,160 KB
testcase_22 AC 106 ms
17,216 KB
testcase_23 AC 76 ms
16,172 KB
testcase_24 AC 114 ms
18,688 KB
testcase_25 AC 146 ms
17,804 KB
testcase_26 AC 110 ms
17,736 KB
testcase_27 AC 72 ms
17,528 KB
testcase_28 AC 73 ms
17,832 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
  }
}
0