結果

問題 No.294 SuperFizzBuzz
ユーザー wing3196wing3196
提出日時 2015-10-23 22:59:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 145,916 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 07:24:51
合計ジャッジ時間 2,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define int long long

const int num[2] = { 3, 5 };
int N, cnt;
string ans;
int memo[30][15];

int DFS(int dep, int rest, string s)
{
	if (cnt == N) return 0;
	if (dep == 0)
	{
		if (rest) return 0;
		if (++cnt == N) ans = s;
		return 1;
	}
	if (memo[dep][rest] != -1 && cnt + memo[dep][rest] < N)
	{
		cnt += memo[dep][rest];
		return memo[dep][rest];
	}
	memo[dep][rest] = 0;
	for (int i = 0; i < 2; i++)
	{
		memo[dep][rest] += DFS(dep - 1, (rest * 10 + num[i]) % 15, s + "35"[i]);
	}
	return memo[dep][rest];
}

signed main()
{
	fill_n((int*)memo, 30 * 15, -1);
	cin >> N;
	for (int i = 1; ; i++)
	{
		DFS(i, 0, "");
		if (cnt == N) break;
	}
	cout << ans << endl;
	return 0;
}
0