結果

問題 No.220 世界のなんとか2
コンテスト
ユーザー tottoripaper
提出日時 2015-06-14 11:33:23
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 514 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 166 ms
コンパイル使用メモリ 40,576 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-28 10:07:23
合計ジャッジ時間 929 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstring>

int p;
long long dp[19][10][2];

long long rec(int index, int remainder, bool hasThree){
    if(index == p){return remainder == 0 || hasThree;}
    
    auto& res = dp[index][remainder][hasThree];
    if(res != -1){return res;}

    res = 0;
    for(int i=0;i<=9;i++){
        res += rec(index+1, (remainder+i) % 3, hasThree || i == 3);
    }

    return res;
}

int main(){
    scanf("%d", &p);
    memset(dp, -1ll, sizeof(dp));
    printf("%lld\n", rec(0, 0, false) - 1);
}
0