結果

問題 No.294 SuperFizzBuzz
コンテスト
ユーザー masa
提出日時 2015-10-23 23:48:48
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,317 ms / 5,000 ms
コード長 1,215 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,007 ms
コンパイル使用メモリ 93,304 KB
実行使用メモリ 440,320 KB
最終ジャッジ日時 2026-04-04 03:12:57
合計ジャッジ時間 10,072 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int LIMIT = 30;

long long combination(long long a, long long b) {
	b = min(b, a - b);

	long long ret = 1;
	for (long long i = 1; i <= b; i++) {
		ret = ret * (a - i + 1) / i;
	}
	return ret;
}

int main() {
	int n;

	cin >> n;
	vector<long long> cnt(LIMIT, 0);

	for (int i = 3; i < LIMIT; i++) {
		for (int j = 2; j < i; j += 3) {
			cnt[i] += combination(i - 1, j);
		}
	}

	int order = 0;
	int sum = 0;
	for (int i = 0; i < LIMIT; i++) {
		sum += cnt[i];

		if (sum >= n) {
			order = i;
			sum -= cnt[i];
			break;
		}
	}

	// cout << order << endl;
	// cout << sum << endl;
	// cout << n - sum << endl;

	vector<string> nums(cnt[order], "");
	int idx = 0;

	for (int n5 = 2; n5 < order; n5 += 3) {
		string numstr(order - 1, '3');
		for (int i = 0; i < n5; i++) {
			numstr[numstr.size() - 1 - i] = '5';
		}

		do {
			// cout << numstr << endl;
			// nums.emplace_back(numstr);
			nums[idx] = numstr;
			idx++;
		} while (next_permutation(numstr.begin(), numstr.end()));
	}

	sort(nums.begin(), nums.end());
	cout << nums[n - sum - 1] << '5' << endl;
	return 0;
}
0