結果

問題 No.294 SuperFizzBuzz
ユーザー furafura
提出日時 2020-07-25 16:47:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 556 ms / 5,000 ms
コード長 830 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 206,228 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 16:22:40
合計ジャッジ時間 6,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	lint choose[30][30]={};
	rep(i,30) choose[i][0]=1;
	rep(i,29) rep(j,i+1) choose[i+1][j+1]=choose[i][j]+choose[i][j+1];

	lint num[30]={};
	rep(len,30){
		for(int five=3;five<=len;five+=3){
			num[len]+=choose[len-1][five-1];
		}
	}

	int n; scanf("%d",&n);
	n--;

	int len;
	for(len=0;n>=num[len];len++) n-=num[len];

	int m=len/3;
	vector seq(m,vector(len,3));
	rep(i,m) rep(j,3*(i+1)) seq[i][len-1-j]=5;

	vector<bool> over(m);
	while(1){
		int idx=-1;
		rep(i,m) if(!over[i] && (idx==-1 || seq[idx]>seq[i])) idx=i;
		assert(idx!=-1);
		if(n==0){
			rep(j,len) printf("%d",seq[idx][j]);
			puts("");
			break;
		}
		over[idx]=!next_permutation(seq[idx].begin(),--seq[idx].end());
		n--;
	}

	return 0;
}
0