結果

問題 No.260 世界のなんとか3
ユーザー Luzhiled
提出日時 2016-10-24 04:55:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 161,012 KB
実行使用メモリ 20,488 KB
最終ジャッジ日時 2024-12-23 14:59:29
合計ジャッジ時間 3,507 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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