結果

問題 No.260 世界のなんとか3
ユーザー yui_cute__yui_cute__
提出日時 2020-06-10 17:29:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,823 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 176,560 KB
実行使用メモリ 13,576 KB
最終ジャッジ日時 2023-09-05 13:23:45
合計ジャッジ時間 4,902 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 135 ms
13,320 KB
testcase_04 WA -
testcase_05 AC 28 ms
6,764 KB
testcase_06 AC 19 ms
5,536 KB
testcase_07 AC 92 ms
11,752 KB
testcase_08 AC 67 ms
12,000 KB
testcase_09 WA -
testcase_10 AC 103 ms
10,996 KB
testcase_11 AC 97 ms
12,384 KB
testcase_12 WA -
testcase_13 AC 17 ms
4,544 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 62 ms
8,392 KB
testcase_18 WA -
testcase_19 AC 79 ms
11,844 KB
testcase_20 AC 55 ms
8,608 KB
testcase_21 AC 49 ms
9,168 KB
testcase_22 AC 88 ms
10,412 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    //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