結果

問題 No.294 SuperFizzBuzz
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-10-23 18:34:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 391 ms / 5,000 ms
コード長 1,747 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 87,968 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 17:43:18
合計ジャッジ時間 3,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

long long nCr[51][51];

void init_nCr(){
  memset(nCr, 0, sizeof(nCr));

  nCr[0][0] = 1;

  for(int i = 1; i <= 50; i++){
    for(int j = 0; j <= 50; j++){
      nCr[i][j] += nCr[i - 1][j];
      if(j - 1 >= 0){
        nCr[i][j] += nCr[i - 1][j - 1];
      }
    }
  }
}

int main(){
  int d[25]; // 数値を埋め込まないバージョン
  init_nCr();
  rep(i,0,25){
    int a = 0;
    int keta = i+1;
    for(int j = 3; j <= keta; j+=3){
      a += nCr[keta-1][(j-1)];
    }
    d[i]=a;
  }
  int n;
  cin >> n;
  int k = 0;
  rep(i,0,25){
    if(n-d[i]<=0){
      k = i;
      break;
    }
    n-=d[i];
  }
  rep(i,0,1<<k){
    int a = 5;
    rep(j,0,k){
      if((i>>j)&1){
        a += 5;
      }
      else{
        a += 3;
      }
    }
    if(a%3==0){
      n--;
      if(n==0){
        string s;
        rep(j,0,k){
          if((i>>j)&1){
            s += "5";
          }
          else{
            s += "3";
          }
        }
        reverse(all(s));
        s+="5";
        cout << s << endl;
        break;
      }
    }
  }
  return 0;
}
0