結果

問題 No.286 Modulo Discount Store
ユーザー tsukiotsukio
提出日時 2016-03-13 20:02:04
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 774 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 56,056 KB
最終ジャッジ日時 2023-10-26 03:23:37
合計ジャッジ時間 1,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:42: error: ‘numeric_limits’ was not declared in this scope
   15 |         vector<int> total_prices(1 << n, numeric_limits<int>::max());
      |                                          ^~~~~~~~~~~~~~
main.cpp:15:57: error: expected primary-expression before ‘int’
   15 |         vector<int> total_prices(1 << n, numeric_limits<int>::max());
      |                                                         ^~~

ソースコード

diff #

#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