結果

問題 No.286 Modulo Discount Store
ユーザー Kiona1018Kiona1018
提出日時 2019-09-29 21:08:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 168,624 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-14 07:24:32
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,816 KB
testcase_01 AC 19 ms
8,320 KB
testcase_02 AC 120 ms
11,136 KB
testcase_03 AC 11 ms
7,296 KB
testcase_04 AC 13 ms
7,808 KB
testcase_05 AC 7 ms
6,944 KB
testcase_06 AC 136 ms
11,520 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 106 ms
10,496 KB
testcase_11 AC 11 ms
7,296 KB
testcase_12 AC 11 ms
7,424 KB
testcase_13 AC 120 ms
11,008 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 19 ms
8,320 KB
testcase_17 AC 155 ms
12,032 KB
testcase_18 AC 105 ms
10,496 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 73 ms
9,344 KB
testcase_21 AC 9 ms
6,940 KB
testcase_22 AC 9 ms
6,944 KB
testcase_23 AC 120 ms
11,008 KB
testcase_24 AC 9 ms
6,944 KB
testcase_25 AC 83 ms
9,856 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 AC 83 ms
9,984 KB
testcase_28 AC 136 ms
11,520 KB
testcase_29 AC 7 ms
6,940 KB
testcase_30 AC 7 ms
6,944 KB
testcase_31 AC 44 ms
8,832 KB
testcase_32 AC 44 ms
8,832 KB
testcase_33 AC 9 ms
6,940 KB
testcase_34 AC 9 ms
6,940 KB
testcase_35 AC 18 ms
8,320 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 84 ms
9,856 KB
testcase_38 AC 6 ms
6,940 KB
testcase_39 AC 136 ms
11,520 KB
testcase_40 AC 5 ms
6,944 KB
testcase_41 AC 6 ms
6,944 KB
testcase_42 AC 9 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define chmin(a,b) a = min((a),(b))
using namespace std;
using ll = long long;
const int MAX_S = 1 << 17;
const int INF = 1000000000;

int main()
{
    int n;
    cin >> n;
    vector<int> money(n);
    rep(i, 0, n) cin >> money[i];

    vector<vector<int>> dp(n+1, vector<int>(MAX_S, INF));
    dp[0][0] = 0;
    rep(i, 0, n)
        rep(prev, 0, MAX_S)
            rep(j, 0, n)
            if ((prev & (1 << j)) == 0 and dp[i][prev] != INF)
            {
                int next = prev | (1 << j);
                int prev_cost = 0;
                rep(k, 0, n)
                if ((1 << k) & prev)
                    prev_cost += money[k];
                
                chmin(dp[i+1][next], dp[i][prev] + max(0, money[j] - (prev_cost % 1000)));
                // cout << i << ' ' <<  next << ' ' << prev << ' ' << dp[i+1][next] << endl;
            }
        
    int state = (1 << n) - 1;
    cout << dp[n][state] << endl;
    // cout << cost << endl;
    return 0;
}
0