結果

問題 No.1407 Kindness
ユーザー au7777
提出日時 2021-03-23 19:57:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 3,513 ms
コンパイル使用メモリ 229,112 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-11-25 21:08:13
合計ジャッジ時間 4,866 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
typedef long long int ll;
using namespace std;
using namespace atcoder;
struct edge {
    ll from;
    ll to;
    ll cost;
};
typedef pair<ll, ll> P;
#define MOD 1000000007
ll dp1[100001];
ll dp2[100001];
int main() {
    string n;
    cin >> n;
    memset(dp1, 0, sizeof(dp1));
    memset(dp2, 0, sizeof(dp2));
    dp2[0] = 1;
    for (int i = 1; i <= n.length(); i++) {
        ll tmp = max(0, (n[i - 1] - '0' - 1));
        dp1[i] = (dp1[i - 1] * 45 + dp2[i - 1] * tmp * (tmp + 1) / 2) % MOD;
        if (i >= 2) dp1[i] += 45;
        dp2[i] = dp2[i - 1] * (n[i - 1] - '0') % MOD;
    }
    cout << (dp1[n.length()] + dp2[n.length()]) % MOD << endl;
    return 0;
}
0