結果

問題 No.294 SuperFizzBuzz
ユーザー rickythetarickytheta
提出日時 2015-10-24 00:13:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 2,180 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 153,584 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 04:59:30
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 126 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 80 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 103 ms
4,348 KB
testcase_12 AC 112 ms
4,348 KB
testcase_13 AC 120 ms
4,348 KB
testcase_14 AC 125 ms
4,348 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];
    }
  }

  // iter is result digit count
  vector<pii> digits = digit_comb[iter];
  // bit 1 means '5'
  // bit 0 means '3'
  vi available;
  REP(i,digits.size())available.push_back(digits[i].first);

  // ll now = cnt - beforecnt;
  ll countdown = n-beforecnt-1;
  ll now = 0;
  // FOR(t,(1<<(iter-1)),(1<<iter)){
  REP(t,(1<<iter)){
    int bc = __builtin_popcount(t);
    if(t%2==0)continue;
    bool flag = false;
    REP(i,available.size()){
      if(available[i]==bc){
        flag = true;
        break;
      }
    }
    if(!flag)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