結果

問題 No.294 SuperFizzBuzz
ユーザー Yang33Yang33
提出日時 2016-10-18 01:47:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 403 ms / 5,000 ms
コード長 1,956 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 74,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 15:58:48
合計ジャッジ時間 3,525 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX


using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(int (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl

llong n;
llong comb[31][31];

void calcomb() {
    int  i, j;
    for (i = 0; i <= 30; i++) {
        for (j = 0; j <= i; j++) {
            if (j == 0 || j == i)
                comb[i][j] = 1;
            else
                comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
        }
    }
}


llong exsum(int a) {
    llong ans = 0;
    FOR(i, 0, a) {
        if ((i + 1) % 3 == 0) {
            ans += comb[a - 1][i];
        }
    }
    return ans;
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    cin >> n;
    calcomb();
    llong count = 0;
    /* 桁数発見 */
    int keta;
    FOR(i, 0, 26) {
        keta = i;
        count += exsum(keta);
        if (count >= n) {
            break;
        }
    }
    count = n - (count - exsum(keta));
    int cc = 0;
    string ans="";
    /* 0が3、1が5 */
    FOR(bit, 1, (1 << keta + 1)) {
        int num = bit;
        int check3 = 0;
        while (num != 0) {
            /* 後の3の倍数かチェックのため */
            if (num & 1)
                check3++;
            num = num >> 1;
        }
        /* 最下位は必ず5 */
        if (!(bit & 1))
            continue;
        if (check3 % 3 != 0)
            continue;
        cc++;
        
        if (cc == count) {
            FORR(i,keta-1,-1) {
                if (bit&(1 << i))
                    ans += "5";
                else ans += "3";
            }
            cout << ans << endl;
            return 0;
        }


    }


    return 0;
}
0