結果

問題 No.260 世界のなんとか3
ユーザー oevloevl
提出日時 2019-03-12 12:19:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,207 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 167,084 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2023-09-05 20:20:23
合計ジャッジ時間 4,554 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,840 KB
testcase_01 AC 5 ms
10,908 KB
testcase_02 AC 5 ms
10,868 KB
testcase_03 AC 116 ms
10,936 KB
testcase_04 AC 117 ms
10,952 KB
testcase_05 AC 26 ms
10,952 KB
testcase_06 AC 19 ms
10,936 KB
testcase_07 AC 80 ms
10,984 KB
testcase_08 AC 58 ms
10,956 KB
testcase_09 AC 35 ms
10,956 KB
testcase_10 AC 91 ms
10,892 KB
testcase_11 WA -
testcase_12 AC 52 ms
10,972 KB
testcase_13 AC 19 ms
10,952 KB
testcase_14 AC 78 ms
10,888 KB
testcase_15 WA -
testcase_16 AC 68 ms
10,940 KB
testcase_17 AC 55 ms
10,868 KB
testcase_18 WA -
testcase_19 AC 68 ms
10,928 KB
testcase_20 AC 49 ms
10,860 KB
testcase_21 WA -
testcase_22 AC 77 ms
11,076 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 79 ms
10,976 KB
testcase_26 AC 44 ms
10,896 KB
testcase_27 AC 4 ms
10,888 KB
testcase_28 AC 85 ms
10,924 KB
testcase_29 AC 151 ms
10,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
#define MOD 1000000007

template <class T> void add(T &a, T b) { a = (a + b) % MOD; }

ll solve(string S) {
  ll dp[10005][2][3][8][2] = {};
  dp[0][0][0][0][0] = 1;
  int len = S.size();
  rep(i, len) rep(j, 2) rep(k, 3) rep(l, 8) rep(m, 2) {
    int x = j ? 9 : S[i] - '0';
    rep(d, x + 1) {
      add(dp[i + 1][j || d < x][(k + d) % 3][(10 * l + d) % 8][m || d == 3],
          dp[i][j][k][l][m]);
    }
  }
  ll ans = 0;
  rep(j, 2) rep(k, 3) rep(l, 8) rep(m, 2) {
    if (l == 0)
      continue;
    if (k == 0 || m)
      add(ans, dp[len][j][k][l][m]);
  }
  return ans;
}

bool hasThree(int num) {
  while (num > 0) {
    if (num % 10 == 3)
      return true;
    num /= 10;
  }
  return false;
}

bool isVailed(string S) {
  bool three = false;
  int num;
  if (S.size() > 3)
    num = stoi(S.substr(S.size() - 3, S.size()));
  else
    num = stoi(S);
  if (num % 8 == 0)
    return false;
  return (num % 3 == 0) || hasThree(num);
}

int main() {
  string A, B;
  cin >> A >> B;
  ll ans = solve(B) - solve(A) + isVailed(A) + MOD;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}
0