結果

問題 No.260 世界のなんとか3
ユーザー LuzhiledLuzhiled
提出日時 2016-10-24 04:55:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 146,056 KB
実行使用メモリ 20,332 KB
最終ジャッジ日時 2023-08-25 02:58:35
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,224 KB
testcase_01 AC 7 ms
19,256 KB
testcase_02 AC 7 ms
19,260 KB
testcase_03 AC 66 ms
20,172 KB
testcase_04 AC 68 ms
20,116 KB
testcase_05 AC 29 ms
19,644 KB
testcase_06 AC 20 ms
19,496 KB
testcase_07 AC 58 ms
20,152 KB
testcase_08 AC 60 ms
20,080 KB
testcase_09 AC 32 ms
19,696 KB
testcase_10 AC 53 ms
20,080 KB
testcase_11 AC 61 ms
20,332 KB
testcase_12 AC 49 ms
19,856 KB
testcase_13 AC 14 ms
19,244 KB
testcase_14 AC 58 ms
20,040 KB
testcase_15 AC 18 ms
19,344 KB
testcase_16 AC 48 ms
19,816 KB
testcase_17 AC 35 ms
19,816 KB
testcase_18 AC 33 ms
19,612 KB
testcase_19 AC 56 ms
20,000 KB
testcase_20 AC 39 ms
19,712 KB
testcase_21 AC 42 ms
19,728 KB
testcase_22 AC 49 ms
19,884 KB
testcase_23 AC 11 ms
19,176 KB
testcase_24 AC 55 ms
19,960 KB
testcase_25 AC 69 ms
20,244 KB
testcase_26 AC 65 ms
20,204 KB
testcase_27 AC 7 ms
19,124 KB
testcase_28 AC 9 ms
20,148 KB
testcase_29 AC 9 ms
20,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mod = 1e9 + 7;

string a, b;

int dp[10101][2][2][2][25];

int dfs(int i=0, bool atight=true, bool btight=true, bool f=false, int sum=0)
{
  int &ret = dp[i][atight][btight][f][sum];

  if (ret != -1) return ret;
  if (i == a.size()){
    return (((sum % 8) != 0) && (f || (sum % 3) == 0));
  }

  int ax = a[i] - '0';
  int bx = b[i] - '0';

  int ar = (atight ? ax : 0);
  int br = (btight ? bx : 9);

  ret = 0;
  for (int j = ar; j <= br; j++){
    ret += dfs(i + 1, atight && j == ax, btight && j == bx, f || j == 3, (sum * 10 + j) % 24);
    ret %= mod;
  }

  return ret;
}

signed main()
{
  cin >> a >> b;

  while (a.size() < b.size()) a = "0" + a;

  memset(dp, -1, sizeof(dp));
  cout << dfs() << endl;
}

0