結果

問題 No.294 SuperFizzBuzz
ユーザー airisairis
提出日時 2015-10-24 02:03:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 741 ms / 5,000 ms
コード長 1,623 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 78,108 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 05:19:33
合計ジャッジ時間 5,624 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}


0