結果

問題 No.260 世界のなんとか3
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-05 16:36:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,773 bytes
コンパイル時間 11,727 ms
コンパイル使用メモリ 492,488 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-11 11:54:57
合計ジャッジ時間 14,502 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 100 ms
4,348 KB
testcase_04 AC 100 ms
4,352 KB
testcase_05 AC 19 ms
4,352 KB
testcase_06 AC 14 ms
4,348 KB
testcase_07 AC 67 ms
4,352 KB
testcase_08 AC 46 ms
4,348 KB
testcase_09 AC 26 ms
4,352 KB
testcase_10 AC 76 ms
4,352 KB
testcase_11 AC 70 ms
4,372 KB
testcase_12 AC 42 ms
4,352 KB
testcase_13 AC 13 ms
4,352 KB
testcase_14 AC 63 ms
4,352 KB
testcase_15 AC 17 ms
4,352 KB
testcase_16 AC 56 ms
4,352 KB
testcase_17 AC 44 ms
4,376 KB
testcase_18 AC 42 ms
4,352 KB
testcase_19 AC 55 ms
4,352 KB
testcase_20 AC 38 ms
4,356 KB
testcase_21 AC 34 ms
4,352 KB
testcase_22 AC 64 ms
4,352 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 48 ms
4,352 KB
testcase_25 AC 59 ms
4,352 KB
testcase_26 AC 39 ms
4,352 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 101 ms
4,352 KB
testcase_29 AC 121 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/260/
#include <bits/stdc++.h>
using namespace std;

#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

#include "atcoder/all"
using namespace atcoder;

using Mint = modint1000000007;

Mint maine(string S) {
    vector bef(2, vector(3, vector(2, vector<Mint>(8))));
    vector<int> tens{1};
    int N = (int)S.size();
    for (int i = 0; i < N - 1; i++) {
        tens.emplace_back((tens[i] * 10) % 8);
    }
    reverse(tens.begin(), tens.end());
    bef[1][0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        char c = S[i];
        int n = (int)(c - '0');
        vector now(2, vector(3, vector(2, vector<Mint>(8))));
        for (int flag = 0; flag < 2; flag++) {
            for (int mod3 = 0; mod3 < 3; mod3++) {
                for (int has3 = 0; has3 < 2; has3++) {
                    for (int mod8 = 0; mod8 < 8; mod8++) {
                        for (int num = 0; num <= (flag ? n : 9); num++) {
                            now[flag && (num == n)][(mod3 + num) % 3][has3 | (num == 3)][(mod8 + num * tens[i]) % 8] += bef[flag][mod3][has3][mod8];
                        }
                    }
                }
            }
        }
        swap(bef, now);
    }
    Mint ret = 0;
    for (int flag = 0; flag < 2; flag++) {
        for (int mod3 = 0; mod3 < 3; mod3++) {
            for (int has3 = 0; has3 < 2; has3++) {
                for (int mod8 = 0; mod8 < 8; mod8++) {
                    ret += bef[flag][mod3][has3][mod8] * ((mod3 == 0) | has3) * (!!mod8);
                }
            }
        }
    }
    return ret;
}

int main() {
    string A, B;
    cin >> A >> B;
    cpp_int A_num(A);
    A_num--;
    A = A_num.str();
    cout << (maine(B) - maine(A)).val() << endl;
}
0