結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー srjywrdnprkt
提出日時 2023-06-19 19:44:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 3,000 ms
コード長 2,554 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 203,476 KB
最終ジャッジ日時 2025-02-14 23:00:44
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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