結果

問題 No.286 Modulo Discount Store
ユーザー silopysilopy
提出日時 2019-11-30 16:32:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 68,240 KB
実行使用メモリ 9,540 KB
最終ジャッジ日時 2024-05-01 02:05:10
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,264 KB
testcase_01 AC 3 ms
8,388 KB
testcase_02 AC 4 ms
8,256 KB
testcase_03 AC 2 ms
8,008 KB
testcase_04 AC 3 ms
8,260 KB
testcase_05 AC 2 ms
8,520 KB
testcase_06 AC 4 ms
8,900 KB
testcase_07 AC 3 ms
8,128 KB
testcase_08 AC 4 ms
8,384 KB
testcase_09 AC 3 ms
8,640 KB
testcase_10 AC 4 ms
8,776 KB
testcase_11 AC 3 ms
8,900 KB
testcase_12 AC 3 ms
7,752 KB
testcase_13 AC 3 ms
7,872 KB
testcase_14 AC 2 ms
8,004 KB
testcase_15 AC 3 ms
8,512 KB
testcase_16 AC 3 ms
8,384 KB
testcase_17 AC 7 ms
7,876 KB
testcase_18 AC 4 ms
8,132 KB
testcase_19 AC 3 ms
9,156 KB
testcase_20 AC 3 ms
7,752 KB
testcase_21 AC 2 ms
7,876 KB
testcase_22 AC 2 ms
7,496 KB
testcase_23 AC 4 ms
8,520 KB
testcase_24 AC 3 ms
7,876 KB
testcase_25 AC 3 ms
8,008 KB
testcase_26 AC 4 ms
9,024 KB
testcase_27 AC 4 ms
7,748 KB
testcase_28 AC 5 ms
7,876 KB
testcase_29 AC 3 ms
8,896 KB
testcase_30 AC 3 ms
7,620 KB
testcase_31 AC 3 ms
8,004 KB
testcase_32 AC 4 ms
8,388 KB
testcase_33 AC 4 ms
8,256 KB
testcase_34 AC 3 ms
8,644 KB
testcase_35 AC 3 ms
7,876 KB
testcase_36 AC 3 ms
8,644 KB
testcase_37 AC 4 ms
9,156 KB
testcase_38 AC 3 ms
8,640 KB
testcase_39 AC 4 ms
7,620 KB
testcase_40 AC 3 ms
9,540 KB
testcase_41 AC 3 ms
8,136 KB
testcase_42 AC 3 ms
8,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
using lint=int64_t;

int N;
int M[20];

int memo[(1<<20)];
int teika[(1<<20)];

int rec(int stat)
{
	if(stat==0)
		return 0;
	if(memo[stat]!=1e9)
		return memo[stat];
	
	int res=1e9;
	for(int i=0;i<N;i++)
	{
		if(!(stat&(1<<i)))continue;

		int nstat=stat&(~(1<<i));
		res=min(res,rec(nstat)+max(0,M[i]-teika[nstat]%1000));
	}

	memo[stat]=res;
	return res;
}

int main()
{
	for(int i=0;i<(1<<20);i++)
		memo[i]=1e9;

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> M[i];
	
	for(int stat=0;stat<(1<<N);stat++)
	{
		for(int j=0;j<N;j++)
		{
			if(stat&(1<<j))
				teika[stat]+=M[j];
		}
	}

	cout << rec((1<<N)-1) << endl;
	return 0;
}
0