結果

問題 No.286 Modulo Discount Store
ユーザー tubo28tubo28
提出日時 2015-10-09 22:40:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 2,400 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 145,164 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2023-09-27 10:04:55
合計ジャッジ時間 3,699 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,496 KB
testcase_01 AC 14 ms
9,468 KB
testcase_02 AC 58 ms
9,516 KB
testcase_03 AC 11 ms
9,552 KB
testcase_04 AC 12 ms
9,484 KB
testcase_05 AC 9 ms
9,616 KB
testcase_06 AC 61 ms
9,548 KB
testcase_07 AC 6 ms
9,468 KB
testcase_08 AC 8 ms
9,468 KB
testcase_09 AC 9 ms
9,528 KB
testcase_10 AC 57 ms
9,636 KB
testcase_11 AC 10 ms
9,732 KB
testcase_12 AC 11 ms
9,468 KB
testcase_13 AC 59 ms
9,464 KB
testcase_14 AC 9 ms
9,492 KB
testcase_15 AC 7 ms
9,516 KB
testcase_16 AC 15 ms
9,464 KB
testcase_17 AC 63 ms
9,472 KB
testcase_18 AC 57 ms
9,492 KB
testcase_19 AC 6 ms
9,504 KB
testcase_20 AC 49 ms
9,480 KB
testcase_21 AC 9 ms
9,496 KB
testcase_22 AC 10 ms
9,576 KB
testcase_23 AC 58 ms
9,544 KB
testcase_24 AC 9 ms
9,500 KB
testcase_25 AC 55 ms
9,540 KB
testcase_26 AC 7 ms
9,572 KB
testcase_27 AC 54 ms
9,660 KB
testcase_28 AC 61 ms
9,468 KB
testcase_29 AC 8 ms
9,644 KB
testcase_30 AC 9 ms
9,532 KB
testcase_31 AC 39 ms
9,468 KB
testcase_32 AC 38 ms
9,604 KB
testcase_33 AC 9 ms
9,464 KB
testcase_34 AC 10 ms
9,496 KB
testcase_35 AC 15 ms
9,488 KB
testcase_36 AC 5 ms
9,492 KB
testcase_37 AC 54 ms
9,480 KB
testcase_38 AC 8 ms
9,468 KB
testcase_39 AC 60 ms
9,472 KB
testcase_40 AC 8 ms
9,484 KB
testcase_41 AC 8 ms
9,484 KB
testcase_42 AC 9 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/8;

int N;
int M[20];
int dp[1<<20];
int sum[1<<20];

int solve(){
    rep(S,1<<20){
        sum[S] = 0;
        rep(i,N)if(S>>i&1) sum[S] += M[i];
    }
    rep(i,1<<N) dp[i] = inf;
    dp[0] = 0;
    rep(S,1<<N){
        rep(i,N)if(~S>>i&1){
            int p = M[i] - sum[S]%1000;
            if(p < 0) p = 0;
            dp[S|(1<<i)] = min(dp[S|(1<<i)], dp[S] + p);
        }
    }
    return dp[(1<<N)-1];
}

signed main(){
    while(cin >> N){
        rep(i,N) cin >> M[i];
        cout << solve() << endl;
    }
}
0