結果

問題 No.286 Modulo Discount Store
ユーザー 9071tomato
提出日時 2018-06-21 19:11:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 98,172 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-30 17:39:08
合計ジャッジ時間 2,029 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N;
vector<LL> M, dp;






//サブ関数
//入力
void input()
{
	cin >> N;
	dp.resize(1 << N, INF);
	dp[0] = 0;
	REP(i, N) {
		LL tmp;
		cin >> tmp;
		M.push_back(tmp);
	}
}

int disCount(int nowSet, int ignore) {
	int bit = 0;
	int sum = 0;
	nowSet -= (1 << ignore);

	while (nowSet > 0) {
		if (nowSet & 1) {
			sum += M[bit];
		}
		bit++;
		nowSet >>= 1;
	}
	return sum % 1000;
}

//計算
void calc()
{
	REP(i, 1 << N) {
		int j = i;  //着目するbit列の複製
		int bit = 0;//着目するbitの位置

		while (j > 0) {
			if (i&(1 << bit)) {
				LL before = dp[i - (1 << bit)];//ここまでの値段
				LL now = M[bit] - disCount(i, bit);
				now = max(now, 0ll);
				dp[i] = min(dp[i], before + now);
			}
			bit ++;
			j >>= 1;
		}
	}

	cout << dp[(1 << N) - 1] << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}
0