結果
| 問題 |
No.260 世界のなんとか3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-31 09:15:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 181 ms / 2,000 ms |
| コード長 | 2,659 bytes |
| コンパイル時間 | 5,972 ms |
| コンパイル使用メモリ | 298,896 KB |
| 最終ジャッジ日時 | 2025-02-23 19:36:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
// #undef _GLIBCXX_DEBUG
// #undef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#ifdef LOCAL
#include "../algo/debug.hpp"
#else
#define debug(...) void(0)
#endif
constexpr int inf = (1<<30) - 1;
constexpr long long linf = (1LL<<60) - 1;
using ll = long long;
using ld = long double;
#define len(x) int((x).size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define LB(c, x) distance(begin(c), lower_bound(all(c), x))
#define UB(c, x) distance(begin(c), upper_bound(all(c), x))
template <typename T, typename S> inline auto min(const T& a, const S& b) { return(a < b ? a : b); }
template <typename T, typename S> inline auto max(const T& a, const S& b) { return(a > b ? a : b); }
template <typename T, typename S> inline bool chmax(T& a, const S& b) { return(a < b ? a = b, 1 : 0); }
template <typename T, typename S> inline bool chmin(T& a, const S& b) { return(a > b ? a = b, 1 : 0); }
// ------------------------------------------------------------------
void solve() {
string A, B; cin >> A >> B;
using mint = modint1000000007;
auto f = [&](string s) -> mint {
int n = len(s);
vector dp(n + 1, vector<vector<vector<vector<mint>>>>(2, vector<vector<vector<mint>>>(2, vector<vector<mint>>(3, vector<mint>(8, 0)))));
dp[0][0][0][0][0] = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < 2; j++) {
for(int k = 0; k < 2; k++) {
for(int l = 0; l < 3; l++) {
for(int m = 0; m < 8; m++) {
int lim = j ? 9: s[i] - '0';
for(int d = 0; d <= lim; d++) {
dp[i + 1][j || d < lim][k || d == 3][(l + d)%3][(2*m+d)%8] += dp[i][j][k][l][m];
}
}
}
}
}
}
mint ans = 0;
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int k = 0; k < 3; k++) {
for(int l = 1; l < 8; l++) {
if(j == 1 || k == 0) ans += dp[n][i][j][k][l];
}
}
}
}
return ans;
};
A.back() -= 1;
mint ans = f(B) - f(A);
cout << ans.val() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// fixed(cout).precision(12);
int T = 1;
// cin >> T;
while(T--) {
solve();
}
}