結果
問題 | No.260 世界のなんとか3 |
ユーザー |
|
提出日時 | 2017-01-08 17:06:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,847 bytes |
コンパイル時間 | 862 ms |
コンパイル使用メモリ | 83,656 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-17 18:05:16 |
合計ジャッジ時間 | 3,241 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 WA * 14 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)using ll = long long;using namespace std;template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }ll modstr(string s, ll m) {ll q = 0;for (char c : s) q = (q * 10 + (c - '0')) % m;return q;}const int mod = 1e9+7;ll f(string s) {auto cur = vectors(2, 3, 8, 2, ll());auto prv = vectors(2, 3, 8, 2, ll());cur[0][0][0][0] = 1;for (char c : s) {cur.swap(prv);repeat (p,2) repeat (i,3) repeat (j,8) repeat (q,2) cur[p][i][j][q] = 0;repeat (p,2) repeat (i,3) repeat (j,8) repeat (q,2) {repeat (d,10) {bool np;if (d < (c-'0') or p) {np = true;} else if (d == (c-'0')) {np = false;} else {continue;}ll & it = cur[np][(i * 10 + d) % 3][(j * 10 + d) % 8][q or (d == 3)];it = (it + prv[p][i][j][q]) % mod;}}}ll result = 0;repeat (p,2) repeat (i,3) repeat (j,8) repeat (q,2) {if ((i == 0 or q == 1) and j != 0) {result += cur[p][i][j][q];}}return result;}bool g(string s) {return modstr(s, 3) == 0 or whole(count, s, '3') or modstr(s, 8) == 0;}int main() {string a, b; cin >> a >> b;cout << (f(b) - f(a) + g(a) + mod) % mod << endl;return 0;}