結果

問題 No.294 SuperFizzBuzz
ユーザー rickythetarickytheta
提出日時 2015-10-24 00:19:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 1,833 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 150,992 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-11 05:02:29
合計ジャッジ時間 2,556 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 71 ms
4,356 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 5 ms
4,352 KB
testcase_09 AC 45 ms
4,356 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 59 ms
4,348 KB
testcase_12 AC 64 ms
4,348 KB
testcase_13 AC 67 ms
4,352 KB
testcase_14 AC 71 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define MAX_DIGIT 30

ll memo_comb[MAX_DIGIT+1][MAX_DIGIT+1];
void init_comb(){
  REP(i,MAX_DIGIT+1)REP(j,MAX_DIGIT+1){
    ll ans = 0;
    if(i<j)ans=0;
    else if(i==j || i==0 || j==0)ans=1;
    else ans = memo_comb[i-1][j]+memo_comb[i-1][j-1];
    memo_comb[i][j]=ans;
  }
}

int main(){
  init_comb();
  ll n;
  cin >> n;
  vector<pii> digit_comb[MAX_DIGIT+1];
  REPR(c5,30)REP(c3,30){
    if(c5*3+c3>MAX_DIGIT)continue;
    digit_comb[c5*3+c3].push_back(make_pair((int)c5*3,(int)c3));
  }

  ll beforecnt = 0;
  ll cnt = 0;
  ll iter = 0;
  while(cnt < n){
    beforecnt = cnt;
    ++iter;
    vector<pii> digits = digit_comb[iter];
    if(digits.empty())continue;
    REP(i,digits.size()){
      pii c53 = digits[i];
      cnt += memo_comb[c53.first+c53.second-1][c53.second];
    }
  }

  // bit 1 means '5'
  // bit 0 means '3'

  ll countdown = n-beforecnt-1;
  ll now = 0;
  ll t = -1;
  while(true){
    t += 2;
    int bc = __builtin_popcount(t);
    if(bc%3 != 0)continue;
    if(now!=countdown){
      ++now;
      continue;
    }
    ll tmp = t;
    string res = "";
    while(res.size() != iter){
      if(tmp%2)res += '5';
      else res += '3';
      tmp /= 2;
    }
    reverse(ALL(res));
    cout << res << endl;
    return 0;
  }
  return 0;
}
0