結果

問題 No.1407 Kindness
ユーザー zuminzumin
提出日時 2021-02-27 19:44:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 763 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 149,256 KB
実行使用メモリ 814,080 KB
最終ジャッジ日時 2024-04-10 15:49:31
合計ジャッジ時間 5,668 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 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 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/all>
#include <vector>
#include <map>

using namespace std;
using namespace atcoder;

using mint=modint1000000007;

mint retsum(string n,map<string,mint>& dp){
    if(dp.count(n)) return dp[n];
    mint t=mint(n.back()-'0');
    if(n.length()==1) return t*(t+1)/2;
    string s=n.substr(0,n.length()-1);
    string sminus1=s;

    for(int d=s.length()-1;d>=0;d--){
        if(s[d]=='0'){
            sminus1[d]='9';
        }else{
            sminus1[d]=s[d]-1;
            break;
        }
    }
    
    return dp[n]=t*(t+1)*retsum(s,dp)/2+(t+10)*(9-t)*retsum(sminus1,dp)/2+45;
}

int main(){
    string n;
    vector<mint> su;
    map<string,mint> dp;
    cin>>n;
    
    cout<<retsum(n,dp).val()<<endl;

    return 0;
}
0