結果

問題 No.260 世界のなんとか3
ユーザー ei1333333ei1333333
提出日時 2015-11-03 14:22:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 2,713 ms
コンパイル使用メモリ 146,096 KB
実行使用メモリ 8,336 KB
最終ジャッジ日時 2023-10-11 13:21:14
合計ジャッジ時間 5,045 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,392 KB
testcase_01 AC 5 ms
7,144 KB
testcase_02 AC 4 ms
7,152 KB
testcase_03 AC 100 ms
8,244 KB
testcase_04 AC 100 ms
8,248 KB
testcase_05 AC 23 ms
7,628 KB
testcase_06 AC 17 ms
7,372 KB
testcase_07 AC 69 ms
8,072 KB
testcase_08 AC 49 ms
8,132 KB
testcase_09 AC 30 ms
7,736 KB
testcase_10 AC 77 ms
7,988 KB
testcase_11 AC 73 ms
8,336 KB
testcase_12 AC 45 ms
8,072 KB
testcase_13 AC 16 ms
7,244 KB
testcase_14 AC 66 ms
8,088 KB
testcase_15 AC 21 ms
7,368 KB
testcase_16 AC 59 ms
7,940 KB
testcase_17 AC 47 ms
7,748 KB
testcase_18 AC 46 ms
7,616 KB
testcase_19 AC 58 ms
8,060 KB
testcase_20 AC 42 ms
7,772 KB
testcase_21 AC 38 ms
7,828 KB
testcase_22 AC 66 ms
7,928 KB
testcase_23 AC 10 ms
7,288 KB
testcase_24 AC 52 ms
8,032 KB
testcase_25 AC 53 ms
8,284 KB
testcase_26 WA -
testcase_27 AC 4 ms
7,092 KB
testcase_28 AC 100 ms
8,288 KB
testcase_29 AC 100 ms
8,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int dp[10000][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