結果

問題 No.319 happy b1rthday 2 me
ユーザー te-shte-sh
提出日時 2017-06-21 16:57:33
言語 D
(dmd 2.105.2)
結果
RE  
実行時間 -
コード長 1,542 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 88,052 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 14:42:18
合計ジャッジ時間 4,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(long[]), a = rd[0]-1, b = rd[1];

  auto ai = digits(a), bi = digits(b);

  auto ra = calc(ai) + (a >= 2 ? 1 : 0);
  auto rb = calc(bi) + (b >= 2 ? 1 : 0);

  if (a == 1 || ai[$-1] == 1 && ai[0] == 2) ++ra;

  writeln(rb - ra);
}

auto digits(long n)
{
  int[] r;
  for (; n > 0; n /= 10) r ~= n % 10;
  r.reverse();
  return r;
}

auto calc(int[] a)
{
  auto n = a.length.to!int;

  auto dp1 = new long[][][][](n+1, 2, 2, 7);
  dp1[0][0][0][0] = 1;

  foreach (i; 0..n)
    foreach (j; 0..2)
      foreach (k; 0..2)
        foreach (l; 0..7) {
          auto dm = j ? 9 : a[i];
          foreach (d; 0..dm+1) {
            if (d == 2 && k == 1 && l < 6)
              dp1[i+1][j || d<dm][0][l+1] += dp1[i][j][1][l];
            else
              dp1[i+1][j || d<dm][d == 1][l] += dp1[i][j][k][l];
          }
        }

  auto dp2 = new long[][][][][](n+1, 2, 2, 2, 2);
  dp2[0][0][1][0][0] = 1;

  foreach (i; 0..n)
    foreach (j; 0..2)
      foreach (k; 0..2)
        foreach (l; 0..2)
          foreach (m; 0..2) {
            auto dm = j ? 9 : a[i];
            foreach (d; 0..dm+1)
              dp2[i+1][j || d<dm][k && d == 0][l || k && d == 2][d == 1] += dp2[i][j][k][l][m];
          }

  auto r1 = 0L;
  foreach (j; 0..2)
    foreach (k; 0..2)
      foreach (l; 1..7)
        r1 += dp1[$-1][j][k][l] * l;

  auto r2 = 0L;
  foreach (j; 0..2)
    foreach (k; 0..2)
      r2 += dp2[$-1][j][k][1][1];

  return r1 + r2;
}
0