結果

問題 No.1407 Kindness
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-21 21:30:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,106 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 202,096 KB
実行使用メモリ 7,280 KB
最終ジャッジ日時 2023-09-11 16:37:12
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 6 ms
5,708 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 4 ms
4,384 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 8 ms
7,280 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;
    }
};

ll N;
string S;
vector<mint> bs;

mint solve(int idx){
    if (idx == N-1) return mint(S[idx]-'0');
    
    mint res=0;
    for (int i=1; i<S[idx+1]-'0'; i++) res += bs[N-2-idx] * i;
    
    res += solve(idx+1);

    return res * (S[idx]-'0');
}

int main(){

    cin >> S;
    N = S.size();
    if (N == 1){
        cout << (S[0]-'0')*(S[0]-'0'+1)/2 << endl;
        return 0;
    }
    bs.resize(N);
    mint ans=0;
    bs[0] = 1;
    for (int i=1; i<=N-1; i++){
        bs[i] = bs[i-1] * 45;
        ans += bs[i];
    }

    cout << ans+solve(0) << endl;

    return 0;
}
0