結果

問題 No.294 SuperFizzBuzz
ユーザー keikei
提出日時 2016-10-14 19:43:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 638 ms / 5,000 ms
コード長 805 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 70,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 10:36:26
合計ジャッジ時間 5,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 638 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 32 ms
4,376 KB
testcase_09 AC 351 ms
4,380 KB
testcase_10 AC 347 ms
4,376 KB
testcase_11 AC 587 ms
4,376 KB
testcase_12 AC 603 ms
4,380 KB
testcase_13 AC 616 ms
4,376 KB
testcase_14 AC 631 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
using namespace std;
//最大25桁  longlong 19桁 ⇒ bitでの計算
//3桁 3:0個 4桁 3:1個 5桁 3:2個 ・・・

//全探索 2^25  ⇒  可

int main() {
	int N, c = 0; cin >> N;
	int sum;
	//i : シフト数
	for (int i = 0; ; i++) {
		// n : i-1桁の2進数の値
		for (int n = 0; n < (1 << i);n++) {
			if (!(n & 1)) continue;
			sum = 0;

			//各桁の5の和を求める
			for (int j = 0; j < i;j++) {
				if (n&(1 << j)) {
					sum += 5;
				}
			}
			if (sum % 3 == 0) {
				c++;
				if (c == N) {
					string Ans;
					for (int k = i-1; k >= 0; k--) {
						if (n&(1 << k)) {
							Ans += "5";
						}
						else {
							Ans += "3";
						}
					}
					cout << Ans << endl; return 0;
				}
			}
		}
	}
}
0