結果

問題 No.286 Modulo Discount Store
ユーザー TwizzTwizz
提出日時 2017-05-19 09:39:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 159,576 KB
実行使用メモリ 259,688 KB
最終ジャッジ日時 2023-10-19 02:44:27
合計ジャッジ時間 6,593 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
259,688 KB
testcase_01 AC 86 ms
259,688 KB
testcase_02 AC 88 ms
259,688 KB
testcase_03 AC 86 ms
259,688 KB
testcase_04 AC 86 ms
259,688 KB
testcase_05 AC 87 ms
259,688 KB
testcase_06 AC 88 ms
259,688 KB
testcase_07 AC 89 ms
259,688 KB
testcase_08 AC 86 ms
259,688 KB
testcase_09 AC 85 ms
259,688 KB
testcase_10 AC 86 ms
259,688 KB
testcase_11 AC 85 ms
259,688 KB
testcase_12 AC 85 ms
259,688 KB
testcase_13 AC 86 ms
259,688 KB
testcase_14 AC 85 ms
259,688 KB
testcase_15 AC 85 ms
259,688 KB
testcase_16 AC 85 ms
259,688 KB
testcase_17 AC 93 ms
259,688 KB
testcase_18 AC 96 ms
259,688 KB
testcase_19 AC 67 ms
259,688 KB
testcase_20 AC 67 ms
259,688 KB
testcase_21 AC 67 ms
259,688 KB
testcase_22 AC 67 ms
259,688 KB
testcase_23 AC 69 ms
259,688 KB
testcase_24 AC 68 ms
259,688 KB
testcase_25 AC 68 ms
259,688 KB
testcase_26 AC 68 ms
259,688 KB
testcase_27 AC 68 ms
259,688 KB
testcase_28 AC 70 ms
259,688 KB
testcase_29 AC 68 ms
259,688 KB
testcase_30 AC 67 ms
259,688 KB
testcase_31 AC 68 ms
259,688 KB
testcase_32 AC 69 ms
259,688 KB
testcase_33 AC 69 ms
259,688 KB
testcase_34 AC 68 ms
259,688 KB
testcase_35 AC 68 ms
259,688 KB
testcase_36 AC 68 ms
259,688 KB
testcase_37 AC 68 ms
259,688 KB
testcase_38 AC 67 ms
259,688 KB
testcase_39 AC 71 ms
259,688 KB
testcase_40 AC 67 ms
259,688 KB
testcase_41 AC 66 ms
259,688 KB
testcase_42 AC 67 ms
259,688 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int rec(int, int)’:
main.cpp:17:19: warning: overflow in conversion from ‘ll’ {aka ‘long long int’} to ‘int’ changes value from ‘10000000000’ to ‘1410065408’ [-Woverflow]
   17 |         int res = mod;
      |                   ^~~

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;

int n;
int m[16];
int dp[65537][1000];//これまで取ったものの集合と合計値段のmodでこれからいくらかかるかの最小値
int rec(int s,int p) {
	if (dp[s][p] > 0)return dp[s][p];
	if (s == (1 << n) - 1)return dp[s][p] = 0;
	int res = mod;
	REP(u, n) {
		if (!(s >> u & 1)) {
			res = min(res, rec(s | 1 << u, (p + m[u]) % 1000) + max(0, m[u] - p % 1000));
		}
	}
	return dp[s][p] = res;
}

int main() {
	cin >> n;
	REP(i, n)cin >> m[i];
	memset(dp, -1, sizeof(dp));
	print(rec(0,0));
	return 0;
}
0