結果

問題 No.315 世界のなんとか3.5
ユーザー risujirohrisujiroh
提出日時 2018-09-08 17:37:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,162 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 184,256 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-22 13:39:23
合計ジャッジ時間 18,369 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,504 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 280 ms
4,380 KB
testcase_13 AC 281 ms
4,376 KB
testcase_14 AC 558 ms
4,380 KB
testcase_15 AC 562 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 560 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 560 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 959 ms
4,424 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 800 ms
4,376 KB
testcase_35 AC 1,424 ms
4,380 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;
  int p; cin >> p;
  auto calc = [&](string x, int in) {
    x = "00" + x;
    int n = x.size();
    VV<VV<V<lint>>> dp; assign(dp, 4, 2, 3, 2, 8);
    dp[0][1][0][0][0] = 1;
    for (int i = 0; i < n; i++) {
      assign(dp[i + 1 & 3], 2, 3, 2, 8, 0LL);
      for (int r = 0; r < 3; r++) for (int s = 0; s < 8; s++) for (int d = 0; d < 10; d++) {
        (dp[i + 1 & 3][0][(r + d) % 3][d == 3][2 * s + d & 7] += dp[i & 3][0][r][0][s]) %= mod;
        (dp[i + 1 & 3][0][(r + d) % 3][1][2 * s + d & 7] += dp[i & 3][0][r][1][s]) %= mod;
        if (d > x[i] - '0') continue;
        (dp[i + 1 & 3][d == x[i] - '0'][(r + d) % 3][d == 3][2 * s + d & 7] += dp[i & 3][1][r][0][s]) %= mod;
        (dp[i + 1 & 3][d == x[i] - '0'][(r + d) % 3][1][2 * s + d & 7] += dp[i & 3][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 (p == 8) {
        if (f <= in and (!r or g) and s) (res += dp[n & 3][f][r][g][s]) %= mod;
      }
      else if (p == 80) {
        if (f <= in and (!r or g)) (res += dp[n & 3][f][r][g][s]) %= mod;
        if (!in and x[n - 1] != '0') in = 1;
        if (f <= in and (!r or g) and !s) (res -= dp[n - 1 & 3][f][r][g][s]) %= mod;
      } else {
        if (f <= in and (!r or g)) (res += dp[n & 3][f][r][g][s]) %= mod;
        if (!in and !(x[n - 2] == '0' and x[n - 1] == '0')) in = 1;
        if (f <= in and (!r or g) and !s) (res -= dp[n - 2 & 3][f][r][g][s]) %= mod;
      }
    }
    return res;
  };
  cout << emod(calc(b, 1) - calc(a, 0)) << '\n';
}
0