結果

問題 No.741 AscNumber(Easy)
ユーザー onakaT_Titai
提出日時 2018-10-05 23:16:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 85,200 KB
実行使用メモリ 81,408 KB
最終ジャッジ日時 2024-10-12 13:25:29
合計ジャッジ時間 3,647 ms
ジャッジサーバーID
(参考情報)
judge5 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

Int dp[1000000][10];

int main(){
    Int N; cin >> N;

    dp[1][9] = 1;
    for (int i = 8; i >= 0; i--){
        dp[1][i] = dp[1][i+1] + 1;
    }
    if (N == 1){
        cout << 10 << endl;
        return 0;
    }
    for (int i = 2; i <= N-1; i++){
        for (int j = 9; j >= 0; j--){
            dp[i][j] += dp[i-1][j];
            dp[i][j] %= MOD; 
        }
        for (int j = 8; j >= 0; j--){
            dp[i][j] += dp[i][j+1];
        }
    }
    Int ans = 0;
    for (int i = 9; i > 0; i--){
        ans += dp[N-1][i];
        ans %= MOD;
    }
    for (int i = 1; i <= N-1; i++){
        ans += dp[i][1];
        ans %= MOD;
    }
    ans++;
    ans %= MOD;
    cout << ans << endl;

} 
0