結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー seiyu_kyoproseiyu_kyopro
提出日時 2021-03-06 00:03:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 3,000 ms
コード長 4,532 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 175,756 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-16 12:09:48
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdio>

const long long MOD = 1000000007;
using namespace std;

// Nは桁数が大きい場合があるので文字列として受け取る
string N;
vector<int> n;  // Nの各桁の数字を格納するベクター
long long dp[100010][2][3][3][2][2];
// i : 桁数
// smaller : 既に小さい
// j : 5が何回出てきたか
// k : 2が何回出てきたか
// l : これまでに0以外の数字が出てきたか
// m : 先頭以外で0を含むか

int main() {
    cin >> N;

    //ベクターnを構成
    for (auto a : N) {
        n.push_back(a - '0');
    }
    int l = N.size();  // nの長さ

    dp[0][0][0][0][0][0] = 1;  //初期条件。他は0で初期化されている
    for (int i = 0; i < l; i++) {
        for (int smaller = 0; smaller < 2; smaller++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    for (int l = 0; l < 2; l++){
                        for(int m = 0; m < 2; m++){
                            for (int x = 0; x <= (smaller ? 9 : n[i]); x++) {
                                // cout << i << " " << j << " " << k << " " << l
                                //      << " " << m << " " << endl;
                                if (x == 5) {
                                    dp[i + 1][smaller || x < n[i]][min(j + 1, 2)][k][l || x != 0][m] +=
                                        dp[i][smaller][j][k][l][m];
                                    dp[i + 1][smaller || x < n[i]][min(j + 1, 2)][k][l || x != 0][m] %=
                                        MOD;
                                } else if (x == 2) {
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 1, 2)][l || x != 0][m] +=
                                        dp[i][smaller][j][k][l][m];
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 1, 2)][l || x != 0][m] %=
                                        MOD;
                                } else if (x == 4) {
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 2, 2)][l || x != 0][m] +=
                                        dp[i][smaller][j][k][l][m];
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 2, 2)][l || x != 0][m] %=
                                        MOD;
                                }else if( x == 6) {
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 1, 2)][l || x != 0][m] +=
                                        dp[i][smaller][j][k][l][m];
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 1, 2)][l || x != 0][m] %=
                                        MOD;
                                }else if (x == 8) {
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 3, 2)][l || x != 0][m] +=
                                        dp[i][smaller][j][k][l][m];
                                    dp[i + 1][smaller || x < n[i]][j][min(k + 3, 2)][l || x != 0][m] %=
                                        MOD;
                                } else if(x == 0) {
                                    if(l == 1){
                                        // out
                                        dp[i + 1][smaller || x < n[i]][j][k][l][m || x == 0] +=
                                            dp[i][smaller][j][k][l][m];
                                        dp[i + 1][smaller || x < n[i]][j][k][l][m || x == 0] %= MOD;

                                    }else{
                                        // safe
                                        dp[i + 1][smaller || x < n[i]][j][k][l][m] +=
                                            dp[i][smaller][j][k][l][m];
                                        dp[i + 1][smaller || x < n[i]][j][k][l][m] %= MOD;
                                    }
                                }else{
                                    dp[i + 1][smaller || x < n[i]][j][k][l || x != 0][m] += dp[i][smaller][j][k][l][m];
                                    dp[i + 1][smaller || x < n[i]][j][k][l || x != 0][m] %= MOD;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    long long ans = 0;

    // for (itn i = 0; i < ; i++)
    // {
    //     /* code */
    // }
    

    ans += (dp[l][0][2][2][1][0] + dp[l][1][2][2][1][0])%MOD;
    ans %= MOD;
    cout << ans << endl;

    return 0;
}
0