結果

問題 No.294 SuperFizzBuzz
ユーザー hotpepsihotpepsi
提出日時 2015-12-26 00:31:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,027 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 59,440 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 03:53:31
合計ジャッジ時間 1,801 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 81 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 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 55 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 73 ms
4,348 KB
testcase_12 AC 76 ms
4,348 KB
testcase_13 AC 78 ms
4,348 KB
testcase_14 AC 82 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>

using namespace std;

static inline int popcount(unsigned int b)
{
#ifdef __GNUC__
	return __builtin_popcount(b);
#elif _MSC_VER >= 1400
	return __popcnt(b);
#else
	b = (b & 0x55555555) + (b >> 1 & 0x55555555);
	b = (b & 0x33333333) + (b >> 2 & 0x33333333);
	b = (b & 0x0F0F0F0F) + (b >> 4 & 0x0F0F0F0F);
	b += b >> 8;
	b += b >> 16;
	return b & 0x3F;
#endif
}

int main(int argc, char *argv[]) {
	int C[256][256] = {};
	for (int i = 0; i < 256; ++i) {
		C[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}

	int N, b = 0;
	cin >> N;

	int tot = 0, len;
	for (len = 3; ; ++len) {
		int a = 0;
		for (int j = 3; j <= len; j += 3) {
			a += C[len - 1][j - 1];
		}
		if (tot + a >= N) {
			break;
		}
		tot += a;
	}

	for (int i = tot; i < N; ++i) {
		++b;
		while ((popcount(b) % 3) != 2) {
			++b;
		}
	}

	string ans = "5";
	for (int i = 1; i < len; ++i) {
		ans = (b & 1 ? "5" : "3") + ans;
		b >>= 1;
	}
	cout << ans << endl;

	return 0;
}
0