結果
問題 | No.286 Modulo Discount Store |
ユーザー | Focus_Sash |
提出日時 | 2021-04-27 19:23:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 2,791 bytes |
コンパイル時間 | 1,932 ms |
コンパイル使用メモリ | 204,792 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 14:38:09 |
合計ジャッジ時間 | 3,329 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 4 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 6 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 4 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | AC | 4 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> pl; typedef priority_queue<ll> pq; typedef priority_queue<ll, vl, greater<>> pqr; struct edge { ll from; ll to; ll cost; edge(ll f, ll t, ll c) : from(f), to(t), cost(c) { } }; typedef vector<vector<ll> > Graph; typedef vector<vector<edge> > WGraph; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep3(i, k, n) for(int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define pb emplace_back #define V vector #define SZ(x) (x).size() #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #define uniquify(vec) (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end()) constexpr ll MOD1 = 1e9 + 7; constexpr ll MOD9 = 998244353; constexpr ll INF = MOD1*MOD1+1; ll dnum(ll d){ return to_string(d).length(); } ll power(ll x, ll n){ ll ret=1; while(n>0){ if(n&1) ret = ret * x; x = x*x; n >>= 1; } return ret; } template<typename T> void rsort(V<T> &v){ sort(all(v), greater<T>()); } template<typename T, typename S> std::ostream &operator<<(std::ostream& os, const pair<T, S> &p){ os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> std::ostream &operator<<(std::ostream& os, const vector<T> &v){ int n = v.size(); os << "["; for(int i = 0; i < n; i++){ if(i == n - 1) os << v[i]; else os << v[i] << ", "; } os << "]"; return os; } template <typename T, typename S> std::ostream &operator<<(std::ostream& os, const map<T, S> &mp){ for(auto iter = mp.begin(); iter != mp.end(); iter++){ os << "(" << iter->first << ", " << iter->second << ")" << " "; } return os; } template <typename T> std::ostream &operator<<(std::ostream& os, const set<T> &s){ os << "{"; for(auto c : s) os << c << " "; os << "}"; return os; } template <typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true;} return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true;} return false; } template <typename T> void fin(const T &a){ cout << a << '\n'; exit(0); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vl M(n); rep(i,n) cin >> M[i]; vl T(1<<n); rep(S, 1<<n){ ll sum = 0; rep(i,n){ if(S & (1<<i)) sum += M[i]; } T[S] = sum%1000; } vl dp(1<<n, INF); dp[0] = 0; rep(S, 1<<n){ rep(i,n){ if(S & (1<<i)) continue; chmin(dp[S|(1<<i)], dp[S] + max(0LL, M[i] - T[S])); } } cout << dp[(1<<n)-1] << '\n'; return 0; }