結果

問題 No.294 SuperFizzBuzz
ユーザー le_panda_noirle_panda_noir
提出日時 2020-04-10 22:18:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 898 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 78,088 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 01:00:40
合計ジャッジ時間 1,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int comb[40][40];
int main() {
  int N; cin >> N;

  comb[0][0] = 1;

  rep(i, 40-1) {
    comb[i+1][0] = 1;
    rep(j, 40-1)
      comb[i+1][j+1] = comb[i][j] + comb[i][j+1];
  }

  int tmp = 0;
  rep(i, 30) {
    int n = i + 2;
    int tmp2 = 0;
    for (int k = 2; n >= k; k += 3)
      tmp2 += comb[n][k];

    tmp += tmp2;
    if (tmp < N)
      continue;

    tmp -= tmp2;
    n = 2;
    rep(i, N - tmp) {
      ++n;
      while (__builtin_popcount(n) % 3 != 2)
        ++n;
    }
    vector<int> ans;
    for (; n > 0; n /= 2)
      ans.push_back(n % 2);

    while ((int)ans.size() < i+2)
      ans.push_back(0);

    reverse(ans.begin(), ans.end());
    for (const auto& e : ans)
      cout << (e == 0 ? 3 : 5);
    cout << 5 << endl;
    return 0;
  }

  return 0;
}
0