結果

問題 No.1407 Kindness
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-21 21:36:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 3,060 ms
コンパイル使用メモリ 200,996 KB
実行使用メモリ 15,940 KB
最終ジャッジ日時 2023-09-11 16:41:53
合計ジャッジ時間 4,979 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 75 ms
14,724 KB
testcase_13 AC 17 ms
6,052 KB
testcase_14 AC 22 ms
6,612 KB
testcase_15 AC 69 ms
13,640 KB
testcase_16 AC 41 ms
9,764 KB
testcase_17 AC 29 ms
7,852 KB
testcase_18 AC 27 ms
7,636 KB
testcase_19 AC 62 ms
12,684 KB
testcase_20 AC 51 ms
11,096 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 48 ms
10,644 KB
testcase_24 AC 85 ms
15,860 KB
testcase_25 AC 27 ms
7,436 KB
testcase_26 AC 38 ms
9,220 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 67 ms
13,504 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 76 ms
14,568 KB
testcase_31 AC 17 ms
5,892 KB
testcase_32 AC 105 ms
12,860 KB
testcase_33 AC 36 ms
6,920 KB
testcase_34 AC 78 ms
10,476 KB
testcase_35 AC 30 ms
6,272 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 37 ms
15,940 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;
    }
};

mint f(ll X, ll M, string &N){
    if (X == -1) return 1;
    mint res=0;
    for (int i=1; i<N[M-1-X]-'0'; i++) res += mint(45).pow(X) * i;
    res += f(X-1, M, N) * (N[M-1-X]-'0');
    return res;
}

int main(){

    string N;
    cin >> N;
    ll M = N.size();
    mint ans = 0;
    for (int i=1; i<=M-1; i++) ans += mint(45).pow(i);
    ans += f(M-1, M, N);
    cout << ans << endl;

    return 0;
}
0