結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-19 19:44:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 3,000 ms
コード長 2,554 bytes
コンパイル時間 2,798 ms
コンパイル使用メモリ 209,332 KB
実行使用メモリ 9,368 KB
最終ジャッジ日時 2023-09-09 15:11:50
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 5 ms
4,592 KB
testcase_33 AC 10 ms
6,440 KB
testcase_34 AC 19 ms
9,184 KB
testcase_35 AC 19 ms
9,356 KB
testcase_36 AC 19 ms
9,356 KB
testcase_37 AC 20 ms
9,296 KB
testcase_38 AC 16 ms
9,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll modc = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(modc-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{
        return x == a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint &m) {
        ll t;
        ip >> t;
        m = mint(t);
        return ip;
    }
};

int main(){

    ll N, c, d;
    string S;
    cin >> S;
    N = S.size();
    vector<vector<vector<vector<mint>>>> dp(N+1, vector(3, vector(3, vector<mint>(2))));
    for (int i=1; i<=N; i++) dp[i][0][0][1] = 1;
    dp[0][0][0][0] = 1;

    for (int i=1; i<=N; i++){
        c = S[i-1]-'0';
        for (int j=1; j<=9; j++){
            for (int k=0; k<=2; k++){
                for (int l=0; l<=2; l++){
                    for (int m=0; m<2; m++){
                        int nk=k, nl=l, nm=m;
                        if (m == 0 && c < j) continue;
                        if (c > j) nm=1;
                        if (j % 4 == 0) nk+=2;
                        else if (j % 2 == 0) nk+=1;
                        if (j % 5 == 0) nl+=1;
                        nk = min(nk, 2);
                        nl = min(nl, 2);
                        dp[i][nk][nl][nm] += dp[i-1][k][l][m];
                    }
                }
            }
        }
    }

    cout << (dp[N][2][2][0]+dp[N][2][2][1]) << endl;

    return 0;
}
0