結果

問題 No.220 世界のなんとか2
ユーザー koyoprokoyopro
提出日時 2020-02-19 23:29:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,531 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 158,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 06:10:52
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int P;
// 3を含む桁DP(3を含まない/3を含む), 3を含まない桁DP(3の倍数の余り)
int DP1[20][2], DP2[20][3];

void solve() {
    cin>>P;
    
    DP1[0][0] = 8; // 0を除く
    DP1[0][1] = 1; // 3のみ
    FOR(i,1,P) {
        DP1[i][0] = DP1[i-1][0] * 9; // 含まない * 3を除く9個
        DP1[i][1] = DP1[i-1][0] + DP1[i-1][1] * 10; // 含まない * 3のみ + 含む * 0~9の10個
    }
    
    FOR(k,1,10) if (k!=3) DP2[0][k%3] += 1;
    FOR(i,1,P) REP(j,3) REP(k,10) if (k!=3) {
        DP2[i][(j+k)%3] += DP2[i-1][j];
    }
    
    int ans = 0;
    REP(i,P) {
        ans += DP1[i][1] + DP2[i][0];
    }
    cout << ans << endl;
}
0