結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
taka99_xyz
|
| 提出日時 | 2022-12-22 19:19:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 172 ms / 2,000 ms |
| コード長 | 1,413 bytes |
| コンパイル時間 | 2,263 ms |
| コンパイル使用メモリ | 199,972 KB |
| 最終ジャッジ日時 | 2025-02-09 18:24:46 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PRINT(a) cout << (a) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
int main(){
int n;
cin >> n;
vector<int> m(n);
REP(i,n)cin >> m[i];
vector dp(1 << n,vector<int>(1000,INF));
dp[0][0]=0;
REP(s, 1<<n)REP(md, 1000){
if(dp[s][md]==INF)continue;
REP(x, n){
if(~s & (1<<x)){
int c = max(m[x] - md, 0);
chmin(dp[s | (1<<x)][(md + m[x]) % 1000], dp[s][md]+c);
}
}
}
int ans=INF;
REP(i,1000)chmin(ans,dp[(1<<n)-1][i]);
cout << ans << endl;
}
taka99_xyz