結果

問題 No.294 SuperFizzBuzz
ユーザー startcppstartcpp
提出日時 2015-10-24 00:04:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,046 ms / 5,000 ms
コード長 842 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 52,384 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 04:53:55
合計ジャッジ時間 7,526 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1,046 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 51 ms
4,348 KB
testcase_09 AC 566 ms
4,348 KB
testcase_10 AC 567 ms
4,348 KB
testcase_11 AC 957 ms
4,352 KB
testcase_12 AC 994 ms
4,352 KB
testcase_13 AC 1,021 ms
4,348 KB
testcase_14 AC 1,045 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//(桁数, 上限, 桁合計mod3, 末尾mod5)を状態とした桁DP + 多倍長かな~→面倒くさい
//桁数MAX = 25より、3と5で作る数の候補は高々2^25 + 2^24 + … + 2^0 = 2^26 - 1通り
//半数列挙をすれば余裕そう→今回は全探索してみる

#include <iostream>
using namespace std;

void output( int n, int i ){
	for( int j = n - 1; j >= 0; j-- ){
		cout << (((i >> j) % 2) ? 5 : 3);
	}
	cout << endl;
}

int main()
{
	int x;
	cin >> x;
	x--;
	
	int n;	//桁数
	for( int n = 1; n < 26; n++ ){
		for( int i = 0; i < (1 << n); i++ ){
			if( i % 2 == 0 )
				continue;
			int digitSum = 0;
			for( int j = 0; j < n; j++ )
				digitSum += (((i >> j) % 2) ? 5 : 3);
			if( digitSum % 3 == 0 ){
				if( !x ){
					output(n, i);
					return 0;
				}
				x--;	//カウントダウン
			}
		}
	}
	return 0;
}
0