結果

問題 No.260 世界のなんとか3
ユーザー risujirohrisujiroh
提出日時 2018-09-08 16:28:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,496 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 181,408 KB
実行使用メモリ 18,780 KB
最終ジャッジ日時 2023-08-22 12:11:57
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 107 ms
18,636 KB
testcase_04 AC 107 ms
18,632 KB
testcase_05 AC 22 ms
8,764 KB
testcase_06 AC 15 ms
7,004 KB
testcase_07 AC 71 ms
16,160 KB
testcase_08 AC 54 ms
16,656 KB
testcase_09 AC 29 ms
9,684 KB
testcase_10 AC 82 ms
15,192 KB
testcase_11 AC 76 ms
17,296 KB
testcase_12 AC 49 ms
14,112 KB
testcase_13 AC 12 ms
5,424 KB
testcase_14 AC 72 ms
16,512 KB
testcase_15 AC 17 ms
6,312 KB
testcase_16 AC 60 ms
13,800 KB
testcase_17 AC 49 ms
11,024 KB
testcase_18 AC 47 ms
10,324 KB
testcase_19 AC 61 ms
16,556 KB
testcase_20 AC 44 ms
11,496 KB
testcase_21 AC 39 ms
12,452 KB
testcase_22 AC 66 ms
14,180 KB
testcase_23 AC 7 ms
4,408 KB
testcase_24 AC 53 ms
15,280 KB
testcase_25 AC 58 ms
18,684 KB
testcase_26 AC 44 ms
18,780 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 87 ms
18,636 KB
testcase_29 AC 121 ms
18,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string a, b; cin >> a >> b;
  auto calc = [](string x, int in) {
    int n = x.size();
    VV<VV<V<lint>>> dp; assign(dp, n + 1, 2, 3, 2, 8);
    dp[0][1][0][0][0] = 1;
    for (int i = 0; i < n; i++) for (int r = 0; r < 3; r++) for (int s = 0; s < 8; s++) for (int d = 0; d < 10; d++) {
      (dp[i + 1][0][(r + d) % 3][d == 3][2 * s + d & 7] += dp[i][0][r][0][s]) %= mod;
      (dp[i + 1][0][(r + d) % 3][1][2 * s + d & 7] += dp[i][0][r][1][s]) %= mod;
      if (d > x[i] - '0') continue;
      (dp[i + 1][d == x[i] - '0'][(r + d) % 3][d == 3][2 * s + d & 7] += dp[i][1][r][0][s]) %= mod;
      (dp[i + 1][d == x[i] - '0'][(r + d) % 3][1][2 * s + d & 7] += dp[i][1][r][1][s]) %= mod;
    }
    lint res = 0;
    for (int f = 0; f < 2; f++) for (int r = 0; r < 3; r++) for (int g = 0; g < 2; g++) for (int s = 0; s < 8; s++) if (f <= in and (!r or g) and s) (res += dp[n][f][r][g][s]) %= mod;
    return res;
  };
  cout << emod(calc(b, 1) - calc(a, 0)) << '\n';
}
0