結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | risujiroh |
提出日時 | 2018-09-08 16:37:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,632 bytes |
コンパイル時間 | 4,275 ms |
コンパイル使用メモリ | 182,484 KB |
実行使用メモリ | 8,768 KB |
最終ジャッジ日時 | 2023-08-22 12:25:58 |
合計ジャッジ時間 | 8,431 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,932 KB |
testcase_01 | AC | 2 ms
4,384 KB |
testcase_02 | AC | 6 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,384 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,384 KB |
testcase_06 | AC | 5 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,384 KB |
testcase_12 | AC | 375 ms
4,384 KB |
testcase_13 | AC | 374 ms
4,380 KB |
testcase_14 | AC | 749 ms
4,380 KB |
testcase_15 | AC | 748 ms
4,380 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
#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) { int n = x.size(); VV<VV<V<lint>>> dp; assign(dp, 2, 2, 3, 2, p); dp[0][1][0][0][0] = 1; for (int i = 0; i < n; i++) { assign(dp[i + 1 & 1], 2, 3, 2, p, 0LL); for (int r = 0; r < 3; r++) for (int s = 0; s < p; s++) for (int d = 0; d < 10; d++) { (dp[i + 1 & 1][0][(r + d) % 3][d == 3][(10 * s + d) % p] += dp[i & 1][0][r][0][s]) %= mod; (dp[i + 1 & 1][0][(r + d) % 3][1][(10 * s + d) % p] += dp[i & 1][0][r][1][s]) %= mod; if (d > x[i] - '0') continue; (dp[i + 1 & 1][d == x[i] - '0'][(r + d) % 3][d == 3][(10 * s + d) % p] += dp[i & 1][1][r][0][s]) %= mod; (dp[i + 1 & 1][d == x[i] - '0'][(r + d) % 3][1][(10 * s + d) % p] += dp[i & 1][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 < p; s++) if (f <= in and (!r or g) and s) (res += dp[n & 1][f][r][g][s]) %= mod; return res; }; cout << emod(calc(b, 1) - calc(a, 0)) << '\n'; }