結果

問題 No.294 SuperFizzBuzz
ユーザー mamekinmamekin
提出日時 2016-04-07 22:52:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,266 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 111,596 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 07:14:49
合計ジャッジ時間 1,804 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<vector<vector<int> > > dp(1, vector<vector<int> >(2, vector<int>(3, 0)));
    dp[0][1][1] = 1;

    for(;;){
        vector<vector<int> > nextDp(2, vector<int>(3, 0));
        for(int i=0; i<2; ++i){
            for(int j=0; j<3; ++j){
                nextDp[0][j] += dp.back()[i][j];
                nextDp[1][(j+1)%3] += dp.back()[i][j];
            }
        }
        dp.push_back(nextDp);

        int tmp = nextDp[0][0] + nextDp[1][0];
        if(tmp < n)
            n -= tmp;
        else
            break;
    }

    int a = 0;
    for(int i=dp.size()-1; i>=0; --i){
        if(n <= dp[i][0][a]){
            cout << 3;
        }
        else{
            cout << 5;
            n -= dp[i][0][a];
            a = (a + 2) % 3;
        }
    }
    cout << endl;

    return 0;
}
0