結果

問題 No.286 Modulo Discount Store
ユーザー Kmcode1Kmcode1
提出日時 2015-10-09 22:34:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 96,088 KB
実行使用メモリ 260,008 KB
最終ジャッジ日時 2023-09-27 10:03:17
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
5,508 KB
testcase_02 AC 31 ms
68,996 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,724 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 57 ms
132,476 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 15 ms
36,260 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 30 ms
69,012 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 3 ms
5,548 KB
testcase_17 AC 165 ms
260,008 KB
testcase_18 AC 16 ms
36,220 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 5 ms
11,724 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 30 ms
69,052 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 9 ms
19,968 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 9 ms
19,836 KB
testcase_28 AC 55 ms
132,520 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 4 ms
7,616 KB
testcase_32 AC 5 ms
7,556 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 3 ms
5,604 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 9 ms
19,884 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 56 ms
132,500 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
//#include<quadmath.h>
using namespace std;
int n;
long long int dp[1 << 15][1002];
long long int m[15];
int main() {
	scanf("%d", &n);
	dp[0][0] = 1LL;
	for (int i = 0;i < n;i++) {
		scanf("%lld", &m[i]);
	}

	for (int i = 0;i < (1 << n);i++) {
		for (int j = 0;j < 1002;j++) {
			dp[i][j] = LLONG_MAX;
		}
	}
	dp[0][0] = 0;
	for (int i = 0;i < (1 << n);i++) {
		for (int j = 0;j < 1002;j++) {
			if (dp[i][j] != LLONG_MAX) {
				long long int cost = dp[i][j];
				for (int k = 0;k < n;k++) {
					if ((i >> k) & 1) {
						
					}
					else {
						long long int nex = cost + max(0LL,m[k] - j);
						int nn = j + m[k];
						nn %= 1000;
						dp[i | (1 << k)][nn] = min(dp[i | (1 << k)][nn], nex);
					}
				}
			}
		}
	}
	long long int ans = LLONG_MAX;
	for (int i = 0;i < 1002;i++) {
		ans = min(ans, dp[(1 << n) - 1][i]);
	}
	printf("%lld\n", ans);
	return 0;
}
0