結果

問題 No.220 世界のなんとか2
ユーザー kakira9618kakira9618
提出日時 2015-05-29 23:27:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,594 bytes
コンパイル時間 1,824 ms
コンパイル使用メモリ 82,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 17:07:27
合計ジャッジ時間 1,697 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
    int P;
    cin >> P;
    long long int dp[20][9 * 20 + 1][2] = {{{0}}};
    dp[0][0][0] = 1;
    for (int i = 0; i < P; i++) {
        for (int j = 0; j <= 9 * 20; j++) {
            for (int k = 0; k <= 9; k++) {
                if (j + k > 9 * 20) continue;
                if (k == 3) {
                    dp[i + 1][j + k][1] += dp[i][j][0];
                    dp[i + 1][j + k][1] += dp[i][j][1];
                } else {
                    dp[i + 1][j + k][0] += dp[i][j][0];
                    dp[i + 1][j + k][1] += dp[i][j][1];
                }
            }
        }
    }
    long long int ans = 0;


    for (int j = 0; j <= 9 * 20; j++) {
        
        ans += dp[P][j][1];
        if (j % 3 == 0) {
            ans += dp[P][j][0];
        }
        
    }
    cout << ans - 1 << endl;
/*
    cout << "debug1" << endl;
    for (int j = 0; j <= 9 * 20; j++) {
        for (int k = 0; k <= 1; k++) {
            cout << dp[P][j][k] << " ";
        }
        cout << endl;
    }
    cout << "debug2" << endl;

    int a[] = {3, 6, 9, 12, 13, 15, 18, 21, 23, 24, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 45, 48, 51, 53, 54, 57, 60, 63, 66, 69, 72, 73, 75, 78, 81, 83, 84, 87, 90, 93, 96, 99};

    int debug[19][2] = {{0}};

    for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) {
        int temp = a[i];
        int sum = 0;
        int flag = 0;
        while(temp > 0) {
            sum += temp % 10;
            if (temp % 10 == 3) {
                flag = 1;
            }
            temp /= 10;
        }
        debug[sum][flag]++;
    }

    for (int i = 0; i < 19; i++) {
        for (int j = 0; j < 2; j++) {
            cout << debug[i][j] << " ";
        }
        cout << endl;
    }
    */
    return 0;
}
0