結果

問題 No.286 Modulo Discount Store
ユーザー ransewhaleransewhale
提出日時 2018-12-07 17:13:48
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 850 bytes
コンパイル時間 1,289 ms
コンパイル使用メモリ 145,196 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-12 03:45:33
合計ジャッジ時間 5,096 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 KB
testcase_01 AC 4 ms
4,348 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n;
ll memo[33400],m[20];
bool done[33400];

ll dp(int st){
	int i;
	ll s=0ll;
	if(done[st]){
		return memo[st];
	}
	for(i=0; i<n; ++i){
		if(st&(1<<i)){
			s += m[i];
		}
	}
	for(i=0; i<n; ++i){
		if(st&(1<<i)){
			memo[st] = min(memo[st],dp(st-(1<<i))+max(0ll,m[i]-(s-m[i])%1000));
		}
	}
	return memo[st];
}

int main(void){
	int i;
	fill(done,done+33400,false);
	fill(memo,memo+33400,INFLL);
	done[0] = true;
	memo[0] = 0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> m[i];
	}
	cout << (dp((1<<n)-1)) << endl;
	return 0;
}
0