結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー norikamenorikame
提出日時 2021-03-05 23:36:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 3,000 ms
コード長 3,555 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 208,672 KB
実行使用メモリ 7,744 KB
最終ジャッジ日時 2024-04-16 11:43:54
合計ジャッジ時間 3,455 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 7 ms
5,632 KB
testcase_34 AC 12 ms
7,516 KB
testcase_35 AC 12 ms
7,740 KB
testcase_36 AC 13 ms
7,612 KB
testcase_37 AC 13 ms
7,740 KB
testcase_38 AC 12 ms
7,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
#define v(t) vector<t>
#define p(t) pair<t, t>
#define p2(t, s) pair<t, s>
#define vp(t) v(p(t))

#define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i)
#define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i)
#define repr(i, n) for (int i=((int)(n)-1); i>=0; --i)
#define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i)

#define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr)
#define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define eb emplace_back

#define INF (1e9)
#define LINF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)
#define DEPS (1e-10)

const ll mod = (ll)(1e9)+7;

// auto mod int
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

const v(v(int)) add = { {0,0}, {0,0}, {1,0}, {0,0}, {2,0}, {0,1}, {1,0}, {0,0}, {3,0}, {0,0} };

int main(){
    string n;
    cin >> n;
    int len = sz(n);
    v(v(v(v(mint)))) dp(len, v(v(v(mint)))(2, v(v(mint))(3, v(mint)(3))));
    rep(i, 10) if (i != 0) {
        if (i < (int)(n.front()-'0')) {
            int k0 = min(2, add[i][0]), k1 = min(2, add[i][1]);
            dp.front()[0][k0][k1] += 1;
        }
        else if (i == (int)(n.front()-'0')) {
            int k0 = min(2, add[i][0]), k1 = min(2, add[i][1]);
            dp.front()[1][k0][k1] += 1;
        }
        else break;
    }
    rep2(i, 1, len-1) {
        rep(i2, 10) if (i2 != 0) {
            int k0 = min(2, add[i2][0]), k1 = min(2, add[i2][1]);
            dp[i][0][k0][k1] += 1;
        }
        rep(i2, 10) if (i2 != 0) {
            rep(j0, 3) rep(j1, 3) {
                int k0 = min(2, j0+add[i2][0]), k1 = min(2, j1+add[i2][1]);
                dp[i][0][k0][k1] += dp[i-1][0][j0][j1];
                if (i2 < (int)(n[i]-'0')) dp[i][0][k0][k1] += dp[i-1][1][j0][j1];
                if (i2 == (int)(n[i]-'0')) dp[i][1][k0][k1] += dp[i-1][1][j0][j1];
            }
        }
    }
    mint ans = dp.back()[0][2][2] + dp.back()[1][2][2];
    cout << ans << endl;
    return 0;
}
0