結果

問題 No.294 SuperFizzBuzz
ユーザー かにかに
提出日時 2016-03-14 17:33:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 404 ms / 5,000 ms
コード長 1,935 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 165,388 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 11:17:30
合計ジャッジ時間 4,554 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 404 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 19 ms
6,676 KB
testcase_09 AC 251 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 329 ms
6,676 KB
testcase_12 AC 364 ms
6,676 KB
testcase_13 AC 382 ms
6,676 KB
testcase_14 AC 402 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:64:32: warning: ‘keta’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |         for (int i = 0; i < (1 << keta); i++) {
      |                             ~~~^~~~~~~~

ソースコード

diff #

#include "bits/stdc++.h"
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define Pi pair<int,int>
#define IINF 1e9
#define LINF 1e18
#define vi vector<int>
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

unsigned long long sttoi(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ull gcd(ull a, ull b) {
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll comb(ll n,ll k) {
	ll ans = 1;
	for (ll i = 0; i < min(k, n - k); i++) {
		ans *= n - i;
		ans /= i + 1;
	}
	return ans;
}
int pop[] = { 2,5,8,11,14,17,20,23 };
void solve() {
	int n;
	cin >> n;
	ll sum = 0;
	ll last;
	int keta;
	string C = "";
	for (int i = 2; i < 25; i++) {
		last = sum;
		for (int j = 0; j < (sizeof(pop) / sizeof(int));j++) {
			if (i >= pop[j]) {
				sum += comb(i, pop[j]);
			}
		}
		C = C + '1';
		if (n <= sum) {
			keta = i;
			break;
		}
	}
	int left = n - last;
	int ans = 0;
	for (int i = 0; i < (1 << keta); i++) {
		bool flag = false;
		int pops = 0;
		for (int j = 0; j < keta; j++) {
			if (i & 1 << j)pops++;
		}
		for (int j = 0; j < (sizeof(pop) / sizeof(int)); j++) {
			if (pops == pop[j]) {
				flag = true;
			}
		}
		if (flag) {
			left--;
			if (left == 0){
				ans = i;
				break;
			}
		}
	}
	string bit = "";
	while (ans > 0) {
		char c = '0' + (ans & 1);
		bit = bit + c;
		ans >>= 1;
	}
	reverse(bit.begin(), bit.end());
	while (bit.length() != keta) {
		bit = '0' + bit;
	}
	bit = bit + '1';
	rep(i, bit.length()) {
		if (bit[i] == '1') {
			bit[i] = '5';
		}
		else if (bit[i] == '0') {
			bit[i] = '3';
		}
	}
	P(bit);
}	

int main() {
	solve();
	return 0;
}
0