結果

問題 No.286 Modulo Discount Store
ユーザー Kiona1018Kiona1018
提出日時 2019-09-29 20:52:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,106 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 169,196 KB
実行使用メモリ 596,076 KB
最終ジャッジ日時 2024-04-14 07:24:16
合計ジャッジ時間 7,363 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 307 ms
244,492 KB
testcase_01 AC 1,231 ms
393,980 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 10000000;
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