結果

問題 No.260 世界のなんとか3
ユーザー yui_cute__yui_cute__
提出日時 2020-06-10 17:30:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,829 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 176,600 KB
実行使用メモリ 13,448 KB
最終ジャッジ日時 2023-09-05 13:24:40
合計ジャッジ時間 4,835 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 134 ms
13,344 KB
testcase_04 AC 134 ms
13,352 KB
testcase_05 AC 28 ms
6,740 KB
testcase_06 AC 18 ms
5,484 KB
testcase_07 AC 92 ms
11,736 KB
testcase_08 AC 66 ms
12,056 KB
testcase_09 AC 37 ms
7,528 KB
testcase_10 AC 102 ms
10,992 KB
testcase_11 AC 97 ms
12,560 KB
testcase_12 AC 60 ms
10,184 KB
testcase_13 AC 17 ms
4,836 KB
testcase_14 AC 89 ms
11,984 KB
testcase_15 AC 23 ms
5,036 KB
testcase_16 AC 77 ms
10,160 KB
testcase_17 AC 62 ms
8,304 KB
testcase_18 AC 60 ms
7,524 KB
testcase_19 AC 78 ms
11,744 KB
testcase_20 AC 55 ms
8,648 KB
testcase_21 AC 50 ms
9,152 KB
testcase_22 AC 88 ms
10,428 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 69 ms
11,280 KB
testcase_25 AC 90 ms
13,332 KB
testcase_26 AC 55 ms
13,448 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 102 ms
13,324 KB
testcase_29 AC 171 ms
13,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
ll fun(const string& s){
    vector<vector<vector<vector<ll>>>> dp(s.size() + 1, vector<vector<vector<ll>>>(2, vector<vector<ll>>(2, vector<ll>(24))));
    dp[0][0][0][0] = 1;
    for(int i = 0; i < s.size(); i++){
        int d = s[i] - '0';

        for(int j = 0; j < 2; j++){//下回ってるか否か
            for(int k = 0; k < 2; k++){//3が入ってるかどうか
                for(int mod = 0; mod < 24; mod++){
                    for(int n = 0; n <= (j ? 9 : d); n++){
                        dp[i + 1][j || (n < d)][k || (n == 3)][(mod * 10 + n) % 24] = (dp[i + 1][j || (n < d)][k || (n == 3)][(mod * 10 + n) % 24] + dp[i][j][k][mod]) % MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int j = 0; j < 2; j++){
        for(int mod = 0; mod < 24; mod++){//3が入っていない
            if(mod % 3 == 0 && (mod % 8)) ans = (ans + dp[s.size()][j][0][mod]) % MOD;
        }
        for(int mod = 0; mod < 24; mod++){//いる
            if(mod % 8) ans = (ans + dp[s.size()][j][1][mod]) % MOD;
        }
    }
    return ans;
}
int main(){
    string a, b;
    cin >> a >> b;
    ll ans = (fun(b) - fun(a) + MOD) % MOD;
    //cout << fun(b) << "\n";
    //cout << fun(a) << "\n";
    bool bl = false;
    int mod = (a[0] - '0');
    for(int i = 1; i < a.size(); i++){
        bl |= (a[i] == '3');
        mod = (mod * 10 + a[i] - '0') % 24;
    }
    if(mod % 8 == 0) cout << ans << "\n";
    else{
        bl |= (mod % 3 == 0);
        if(bl) cout << ans + 1 << "\n";
        else cout << ans << "\n";
    }
}
0