結果

問題 No.294 SuperFizzBuzz
ユーザー imulanimulan
提出日時 2016-07-13 17:16:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 1,342 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 164,352 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 16:30:24
合計ジャッジ時間 2,964 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 46 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 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 29 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 36 ms
5,376 KB
testcase_12 AC 40 ms
5,376 KB
testcase_13 AC 42 ms
5,376 KB
testcase_14 AC 45 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N=25;

int main()
{
    //Combinationの計算
    int C[N][N];
    C[0][0]=1;
    for(int i=1; i<N; ++i)
    {
        C[i][0]=1;
        C[i][i]=1;
        for(int j=1; j<i; ++j) C[i][j]=C[i-1][j]+C[i-1][j-1];
    }

    int n;
    cin >>n;

    int ct=0;
    string ans="5";

    //桁数はi+1(一番下は5で確定)
    for(int i=2; i<N; ++i)
    {
        //i+1桁の数でSuperFizzBuzzである数
        int tmp=0;
        for(int j=2; j<=i; j+=3) tmp+=C[i][j];

        if(ct+tmp<n) ct+=tmp;
        else
        {
            //この桁で答えが確定する
            rep(mask,1<<i)
            {
                if(__builtin_popcount(mask)%3==2) ++ct;
                if(ct==n)
                {
                    rep(j,i)
                    {
                        if(mask>>j&1) ans="5"+ans;
                        else ans="3"+ans;
                    }
                    break;
                }
            }
            break;
        }
    }

    cout << ans << endl;
    return 0;
}
0