結果

問題 No.319 happy b1rthday 2 me
ユーザー te-shte-sh
提出日時 2017-06-21 17:09:38
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 88,044 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 14:42:43
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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);

  auto r = rb - ra;

  if (a <= 1 || a > 1 && ai[$-1] == 1 && ai[0] == 2) --r;

  writeln(r);
}

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 == 2] += 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