結果

問題 No.260 世界のなんとか3
ユーザー ei1333333ei1333333
提出日時 2015-11-03 14:24:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 159,476 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-04-25 07:48:43
合計ジャッジ時間 3,637 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,040 KB
testcase_01 AC 5 ms
7,168 KB
testcase_02 AC 5 ms
7,040 KB
testcase_03 AC 92 ms
8,576 KB
testcase_04 AC 93 ms
8,448 KB
testcase_05 AC 21 ms
7,552 KB
testcase_06 AC 16 ms
7,424 KB
testcase_07 AC 64 ms
8,320 KB
testcase_08 AC 46 ms
8,320 KB
testcase_09 AC 28 ms
7,680 KB
testcase_10 AC 71 ms
8,064 KB
testcase_11 AC 69 ms
8,320 KB
testcase_12 AC 42 ms
7,936 KB
testcase_13 AC 16 ms
7,296 KB
testcase_14 AC 62 ms
8,320 KB
testcase_15 AC 20 ms
7,296 KB
testcase_16 AC 54 ms
7,936 KB
testcase_17 AC 44 ms
7,936 KB
testcase_18 AC 42 ms
7,680 KB
testcase_19 AC 54 ms
8,320 KB
testcase_20 AC 40 ms
7,936 KB
testcase_21 AC 35 ms
7,808 KB
testcase_22 AC 62 ms
8,064 KB
testcase_23 AC 10 ms
7,296 KB
testcase_24 AC 49 ms
8,064 KB
testcase_25 AC 49 ms
8,448 KB
testcase_26 AC 49 ms
8,192 KB
testcase_27 AC 4 ms
7,168 KB
testcase_28 AC 93 ms
8,576 KB
testcase_29 AC 93 ms
8,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int dp[10001][2][2][3][8];
int rec(const string& S, int idx, bool free, bool Aho, int three, int eight)
{
  if(idx == S.size()) {
    return((Aho | (three == 0)) & (eight != 0));
  } else if(~dp[idx][free][Aho][three][eight]) {
    return(dp[idx][free][Aho][three][eight]);
  } else {
    int ret = 0;
    for(int i = max< int >(9 * free, S[idx]); i >= 0; i--) {
      (ret += rec(S, idx + 1, free|(i != S[idx]), Aho|(i == 3), (three * 10 + i) % 3, (eight * 10 + i) % 8)) %= MOD;
    }
    return(dp[idx][free][Aho][three][eight] = ret);
  }
}

const int getDP(string S)
{
  for(int i = 0; i < S.size(); i++) S[i] -= '0';
  memset(dp, -1, sizeof(dp));
  return(rec(S, 0, false, false, 0, 0));
}

void Decrement(string& S, int idx)
{
  if(S[idx] == '0') Decrement(S, idx - 1), S[idx] = '9';
  else              S[idx]--;
}


int main()
{
  string A, B;
  cin >> A >> B;
  Decrement(A, A.size() - 1);
  cout << (getDP(B) - getDP(A) + MOD) % MOD << endl;
}
0