結果

問題 No.294 SuperFizzBuzz
ユーザー keikei
提出日時 2016-10-14 19:43:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 618 ms / 5,000 ms
コード長 805 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 69,908 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 23:03:02
合計ジャッジ時間 4,976 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 618 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 30 ms
6,940 KB
testcase_09 AC 328 ms
6,940 KB
testcase_10 AC 323 ms
6,940 KB
testcase_11 AC 556 ms
6,944 KB
testcase_12 AC 557 ms
6,940 KB
testcase_13 AC 587 ms
6,940 KB
testcase_14 AC 593 ms
6,940 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