結果

問題 No.286 Modulo Discount Store
コンテスト
ユーザー tsukio
提出日時 2016-03-13 20:02:04
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 774 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,221 ms
コンパイル使用メモリ 168,032 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:05:54
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;

	vector<int> product_prices(n);
	for (int i = 0; i < n; i++) {
		cin >> product_prices[i];
	}

	vector<int> total_prices(1 << n, numeric_limits<int>::max());
	total_prices[0] = 0;
	
	for (int i = 0; i < total_prices.size() - 1; i++) {
		int total_price = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1 == 1)
				total_price += product_prices[j];
		}
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1 == 1) continue;
			int price = max(0, product_prices[j] - (total_price % 1000));
			total_prices[i | (1 << j)] = min(total_prices[i | (1 << j)], total_prices[i] + price);
		}
	}

	cout << total_prices[total_prices.size() - 1] << endl;
	
	return 0;
}
0