結果

問題 No.220 世界のなんとか2
ユーザー medo_program05medo_program05
提出日時 2020-02-12 01:14:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,200 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 166,660 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 02:46:56
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*yukicoder No.220 世界のなんとか2*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int p;
    cin >> p;
    vector<int> n(p+1);
    n[0] = 1;
    for(int i = 1; i <= p; i++) n[i] = 0;
    ll dp[25][2][2][3] = {0};
    dp[0][0][0][0] = 1;

    // i digits 
    // j less ?
    // k have 3 ? x == 3 -> true
    // r mod 3<--> (remainder + x) % 3 

    for(int i = 0; i <= p; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                for(int r = 0; r < 3; r++){
                    for(int x = 0; x <= (j?9:n[i]); x++){
                        dp[i+1][j || x < n[i]][k || x == 3][(r+x) % 3] += dp[i][j][k][r];
                    }
                }
            }
        }
    }
    //(have 3 + mod 3 - have3 && mod3)
    ll ans = 0;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            ans += dp[p+1][i][j][0];
        }
    }
    ans -= (dp[p+1][0][1][0]+dp[p+1][1][1][0]);
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 3; j++){
            ans += dp[p+1][i][1][j];
        }
    }
    //cout << dp[p+1][0][1][0]+dp[p+1][1][1][0];
    cout << ans-1 << endl;
    return 0; 
}
0