結果
| 問題 |
No.294 SuperFizzBuzz
|
| コンテスト | |
| ユーザー |
airis
|
| 提出日時 | 2015-10-24 02:03:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 722 ms / 5,000 ms |
| コード長 | 1,623 bytes |
| コンパイル時間 | 686 ms |
| コンパイル使用メモリ | 83,932 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 04:36:48 |
| 合計ジャッジ時間 | 5,129 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;
ll N;
string ans;
ll C[1005][1005];
void combination(int size) {
for (int i = 0; i < size; i++) C[i][0] = 1LL;
for (int i = 1; i < size; i++) {
for (int j = 1; j <= i; j++) {
C[i][j] = (C[i-1][j-1] + C[i-1][j]);
}
}
}
ll count(int d) {
ll res = 0;
for (int i = 0; i < d; i++) {
if ((i + 1) % 3 != 0) continue;
res += C[d - 1][i];
}
return res;
}
string calc(int d, int g) {
string res = "";
int mask = 0;
for (; mask < (1 << d); mask++) {
int bitcount = 0;
rep(i, d) if (mask & (1 << i)) bitcount++;
if ((mask & 1) == 1 && bitcount % 3 == 0) g--;
if (g == 0) break;
}
for (int i = d - 1; i >= 0; i--) {
if (mask & (1 << i)) res += '5';
else res += '3';
}
return res;
}
void solve() {
combination(35);
ll cur = 0;
for (int d = 1; d < 30; d++) {
ll num = count(d);
if (num + cur >= N) {
ans = calc(d, N - cur);
break;
}
cur += num;
}
cout << ans << endl;
}
int main() {
cin >> N;
solve();
return 0;
}
airis