結果

問題 No.260 世界のなんとか3
ユーザー kimiyukikimiyuki
提出日時 2017-01-08 17:35:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,858 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 84,160 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 17:39:13
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 84 ms
4,380 KB
testcase_04 AC 84 ms
4,380 KB
testcase_05 AC 17 ms
4,380 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 57 ms
4,380 KB
testcase_08 AC 40 ms
4,376 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 66 ms
4,376 KB
testcase_11 AC 60 ms
4,376 KB
testcase_12 AC 37 ms
4,376 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 56 ms
4,376 KB
testcase_15 AC 15 ms
4,384 KB
testcase_16 AC 49 ms
4,380 KB
testcase_17 AC 39 ms
4,380 KB
testcase_18 AC 37 ms
4,376 KB
testcase_19 AC 48 ms
4,376 KB
testcase_20 AC 34 ms
4,380 KB
testcase_21 AC 31 ms
4,384 KB
testcase_22 AC 55 ms
4,380 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 43 ms
4,376 KB
testcase_25 AC 50 ms
4,380 KB
testcase_26 AC 37 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 73 ms
4,376 KB
testcase_29 AC 99 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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')) and modstr(s, 8) != 0;
}
int main() {
    string a, b; cin >> a >> b;
    cout << ((f(b) - f(a) + g(a)) % mod + mod) % mod << endl;
    return 0;
}
0