結果

問題 No.220 世界のなんとか2
ユーザー albicillaalbicilla
提出日時 2015-12-26 15:49:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 680 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 58,200 KB
実行使用メモリ 5,676 KB
最終ジャッジ日時 2023-10-19 04:05:49
合計ジャッジ時間 1,260 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int mod = 1e9 + 7;
int dp[101010][2][2][3]; // pos, less, has3, mod3

int main() {
    string A;
    cin >> A;
    int n = A.length();

    dp[0][0][0][0] = 1;
    rep (i, n) rep (j, 2) rep (k, 2) rep (l, 3) {
        int lim = j ? 9 : A[i] - '0';
        rep (d, lim + 1) {
            (dp[i + 1][j || d < lim][k || d == 3][(l + d) % 3] += dp[i][j][k][l]) %= mod;
        }
    }

    int ans = 0;
    rep (j, 2) rep (k, 2) rep (l, 3) {
        if (k || l == 0)  {
            (ans += dp[n][j][k][l]) %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}
0