結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
Ryu
|
| 提出日時 | 2018-06-17 15:31:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,382 bytes |
| コンパイル時間 | 1,560 ms |
| コンパイル使用メモリ | 171,952 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 16:31:20 |
| 合計ジャッジ時間 | 2,857 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
int to, cost;
};
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dp[1 << 16];
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> M(N);
REP(i, N)
{
cin >> M[i];
}
vector<ll> money(1 << N);
REP(S, 1 << N)
{
REP(i, N)
{
if((S >> i) & 1)
{
money[S] += M[i] % 1000;
}
money[S] %= 1000;
}
}
REP(i, 1 << N)
{
dp[i] = llINF;
}
dp[0] = 0;
ll ans = 0;
REP(S, 1 << N)
{
REP(i, N)
{
if((S << i) & 1) continue;
int now = M[i] - money[S];
if(now < 0)
{
now = 0;
}
dp[S | 1 << i] = min(dp[S | 1 << i], dp[S] + now);
}
}
cout << dp[(1 << N) - 1] << endl;
return 0;
}
Ryu