結果

問題 No.260 世界のなんとか3
ユーザー sonotarousonotarou
提出日時 2022-09-13 23:16:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 201,152 KB
実行使用メモリ 41,576 KB
最終ジャッジ日時 2023-08-21 00:11:26
合計ジャッジ時間 6,425 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
41,188 KB
testcase_01 AC 18 ms
41,308 KB
testcase_02 AC 18 ms
41,312 KB
testcase_03 AC 131 ms
41,264 KB
testcase_04 AC 131 ms
41,576 KB
testcase_05 AC 39 ms
41,392 KB
testcase_06 AC 32 ms
41,280 KB
testcase_07 AC 94 ms
41,352 KB
testcase_08 AC 71 ms
41,296 KB
testcase_09 AC 46 ms
41,404 KB
testcase_10 AC 104 ms
41,292 KB
testcase_11 AC 98 ms
41,216 KB
testcase_12 AC 66 ms
41,208 KB
testcase_13 AC 32 ms
41,280 KB
testcase_14 AC 92 ms
41,280 KB
testcase_15 AC 38 ms
41,320 KB
testcase_16 AC 82 ms
41,220 KB
testcase_17 AC 68 ms
41,408 KB
testcase_18 AC 67 ms
41,216 KB
testcase_19 AC 81 ms
41,480 KB
testcase_20 AC 62 ms
41,208 KB
testcase_21 AC 57 ms
41,404 KB
testcase_22 AC 92 ms
41,292 KB
testcase_23 AC 24 ms
41,256 KB
testcase_24 AC 75 ms
41,476 KB
testcase_25 AC 84 ms
41,496 KB
testcase_26 AC 64 ms
41,312 KB
testcase_27 AC 18 ms
41,320 KB
testcase_28 AC 111 ms
41,332 KB
testcase_29 AC 150 ms
41,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define overload(_1, _2, _3, name, ...) name
#define _for(i, a, b) for(int i = int(a); i<int(b); ++i)
#define _rep(i, n) _for(i, 0, n)
#define rep(...) overload(__VA_ARGS__, _for, _rep,)(__VA_ARGS__)
#define _rfor(i, a, b) for(int i = int(a) - 1; i >= int(b); --i)
#define _rrep(i, n) _rfor(i, n, 0)
#define rrep(...) overload(__VA_ARGS__, _rfor, _rrep,)(__VA_ARGS__)
template<class T> inline bool chmax(T&a, T b){ if(a < b){a = b; return 1;} return 0; }
template<class T> inline bool chmin(T&a, T b){ if(a > b){a = b; return 1;} return 0; }

const int mod = 1e9 + 7;
string a, b;
int dp[101010][2][2][3][8];

int main () {
    cin.tie(0) -> sync_with_stdio(false);

    cin >> a >> b;
   
    auto calc = [&](string s, int f) {
        memset(dp, 0, sizeof(dp));
        dp[0][0][0][0][0] = 1;
        int n = s.size();
  
        rep(i, n)rep(j, 2)rep(k, 2)rep(l, 3)rep(m, 8) {
            rep(d, (j ? 9 : s[i] - '0') + 1) {
                (dp[i + 1][j || d < s[i] - '0'][k || d == 3][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m]) %= mod;
            }
        }

        int sum = 0;
        rep(k, 2)rep(l, 3)rep(m, 8) {
            if((k || l == 0) && m) {
                (sum += dp[n][1][k][l][m]) %= mod;
                if(f) (sum += dp[n][0][k][l][m]) %= mod; 
            }
        }

        return sum;
    };

    cout << (calc(b, 1) - calc(a, 0) + mod) % mod << '\n';

    return 0;
}
0