結果

問題 No.1904 Never giving up!
ユーザー publflpublfl
提出日時 2022-04-15 21:33:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 31,816 KB
実行使用メモリ 191,928 KB
最終ジャッジ日時 2023-08-26 07:36:48
合計ジャッジ時間 6,859 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
179,996 KB
testcase_01 AC 73 ms
189,280 KB
testcase_02 AC 142 ms
189,284 KB
testcase_03 AC 75 ms
189,300 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 52 ms
191,804 KB
testcase_08 AC 50 ms
191,808 KB
testcase_09 AC 51 ms
191,812 KB
testcase_10 AC 58 ms
191,804 KB
testcase_11 AC 151 ms
191,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int a;
int x[110];
long long int check[21][2000010];
long long int func(int last, int bit)
{
	if(bit+1==(1<<a)) return 1;
	if(check[last][bit]!=-1) return check[last][bit];
	
	long long int ans = 0;
	for(int i=1;i<=a;i++)
	{
		if(((bit>>(i-1))&1)==0 && x[last]<=x[i])
		{
			int t = func(i,bit+(1<<(i-1)));
			ans+=t;
		}
	}
	return check[last][bit] = ans;
}

int main()
{
	for(int i=1;i<=20;i++) for(int j=0;j<=(1<<20);j++) check[i][j] = -1;
	
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	
	long long int ans = 0;
	for(int i=1;i<=a;i++) ans += func(i,1<<(i-1));
	
	long long int ans2 = 1;
	for(int i=1;i<=a;i++) ans2*=i;
	printf("%lld",ans2/ans);
}
0