結果

問題 No.294 SuperFizzBuzz
ユーザー h_nosonh_noson
提出日時 2016-06-08 15:56:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 1,370 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 68,216 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 09:46:13
合計ジャッジ時間 1,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int comb[30][30];

int C(int n, int k) {
    if (n < k)
        return 0;
    else if (comb[n][k] > 0)
        return comb[n][k];
    else if (n == k || k == 0)
        return 1;
    else
        return comb[n][k] = C(n-1,k) + C(n-1,k-1);
}

int main(void) {
    int i, n;
    cin >> n;
    n--;

    int digits = 0;
    while (true) {
        int cnt = 0;
        REP (i,1,digits/3)
            cnt += C(digits-1,digits-i*3);
        if (cnt > n)
            break;
        n -= cnt;
        digits++;
    }

    vector<int> ans;
    for (i = 1; i < 1<<digits; i+=2) {
        if (__builtin_popcount(i) % 3 == 0) {
            if (n == 0) {
                while (digits--) {
                    if (i % 2)
                        ans.push_back(5);
                    else
                        ans.push_back(3);
                    i /= 2;
                }
                break;
            }
            n--;
        }
    }
    reverse(ans.begin(),ans.end());
    for (auto x : ans) cout << x;
    cout << endl;
    return 0;
}
0