結果

問題 No.220 世界のなんとか2
ユーザー imulanimulan
提出日時 2016-12-09 19:18:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 919 bytes
コンパイル時間 3,479 ms
コンパイル使用メモリ 165,120 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 05:49:02
合計ジャッジ時間 2,553 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

// 上からi桁目まで決定, 3を使ったらj=1, 3での剰余k
ull dp[21][2][3]={};

int main()
{
    int P;
    cin >>P;

    dp[0][0][0]=1;
    for(int i=1; i<=P; ++i)for(int num=0; num<=9; ++num)
    {
        if(num==3)
        {
            rep(j,2)rep(k,3) dp[i][1][k] += dp[i-1][j][k];
        }
        else
        {
            rep(j,2)rep(k,3) dp[i][j][(k+num)%3] += dp[i-1][j][k];
        }
    }
    // 0を排除
    --dp[P][0][0];

    ull ans=0;
    rep(j,2) ans+=dp[P][j][0];
    rep(k,3) ans+=dp[P][1][k];
    ans-=dp[P][1][0];
    cout << ans << endl;
    return 0;
}
0