結果

問題 No.286 Modulo Discount Store
ユーザー whesonwheson
提出日時 2018-05-02 21:09:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 167,664 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 08:56:04
合計ジャッジ時間 3,853 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 AC 28 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 31 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 26 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 28 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 34 ms
4,376 KB
testcase_18 AC 25 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 20 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 29 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 23 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 23 ms
4,376 KB
testcase_28 AC 31 ms
4,384 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 16 ms
4,380 KB
testcase_32 AC 17 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 3 ms
4,384 KB
testcase_35 AC 12 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 23 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 31 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
vector<int> m;
int dp[1 << 16];
/**********************************************/

bool contain(int mask, int pos){
    return ((mask & (1 << pos)) != 0);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    m.assign(n, 0);
    REP(i, n) cin >> m[i];

    REP(i, 1 << 16) dp[i] = INF;
    dp[0] = 0;
    for(int mask = 1; mask < (1 << 16); mask++){
        REP(i, n){
            if(contain(mask, i)){
                int sum = 0;
                REP(j, n){
                    if(contain(mask, j) && j != i){
                        sum += m[j];
                    }
                }

                dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + max(m[i] - (sum % 1000), 0));
            }
        }
    }

    cout << dp[(1 << n) - 1] << endl;
}
0