結果

問題 No.286 Modulo Discount Store
ユーザー OUDONOUDON
提出日時 2017-09-29 23:58:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 1,495 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 166,548 KB
実行使用メモリ 131,660 KB
最終ジャッジ日時 2023-08-09 22:03:38
合計ジャッジ時間 6,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
131,520 KB
testcase_01 AC 38 ms
131,360 KB
testcase_02 AC 127 ms
131,520 KB
testcase_03 AC 38 ms
131,420 KB
testcase_04 AC 38 ms
131,368 KB
testcase_05 AC 37 ms
131,384 KB
testcase_06 AC 230 ms
131,432 KB
testcase_07 AC 37 ms
131,416 KB
testcase_08 AC 38 ms
131,368 KB
testcase_09 AC 37 ms
131,388 KB
testcase_10 AC 79 ms
131,384 KB
testcase_11 AC 38 ms
131,432 KB
testcase_12 AC 38 ms
131,444 KB
testcase_13 AC 127 ms
131,560 KB
testcase_14 AC 37 ms
131,364 KB
testcase_15 AC 36 ms
131,656 KB
testcase_16 AC 39 ms
131,388 KB
testcase_17 AC 446 ms
131,420 KB
testcase_18 AC 79 ms
131,660 KB
testcase_19 AC 36 ms
131,448 KB
testcase_20 AC 46 ms
131,384 KB
testcase_21 AC 36 ms
131,416 KB
testcase_22 AC 37 ms
131,380 KB
testcase_23 AC 126 ms
131,360 KB
testcase_24 AC 38 ms
131,372 KB
testcase_25 AC 57 ms
131,380 KB
testcase_26 AC 38 ms
131,448 KB
testcase_27 AC 57 ms
131,444 KB
testcase_28 AC 228 ms
131,432 KB
testcase_29 AC 37 ms
131,644 KB
testcase_30 AC 38 ms
131,384 KB
testcase_31 AC 42 ms
131,420 KB
testcase_32 AC 42 ms
131,388 KB
testcase_33 AC 37 ms
131,524 KB
testcase_34 AC 38 ms
131,440 KB
testcase_35 AC 39 ms
131,384 KB
testcase_36 AC 37 ms
131,372 KB
testcase_37 AC 55 ms
131,392 KB
testcase_38 AC 37 ms
131,448 KB
testcase_39 AC 228 ms
131,620 KB
testcase_40 AC 37 ms
131,376 KB
testcase_41 AC 37 ms
131,524 KB
testcase_42 AC 37 ms
131,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MOD = 1000;
int dp[1<<15][1000];

int main()
{
    ios::sync_with_stdio(false);
    int N; cin >> N;

    fill(dp[0], dp[0] + (1<<15) * 1000, INF);
    dp[0][0] = 0;

    vector<int> M(N);
    int sum = 0;
    rep(i, N) { cin >> M[i]; sum += M[i]; }
    
    for (int i=0; i<(1<<N); i++) {
        for (int j=0; j<1000; j++) {
            for (int n=0; n<N; n++) {
                if (dp[i][j] < INF && !((i>>n)&1)) {
                    int m = M[n];
                    dp[i|(1<<n)][(j+m)%MOD] = min(dp[i|(1<<n)][(j+m)%MOD], dp[i][j] + max(0, m - j));
#ifdef DEBUG
                    // DUMP(BINARY(i));
                    // cerr << BINARY((i|(1<<n))) << endl;
                    // DUMP(j);
#endif
                }
            }
        }
    }

    // int ans = INF;
    // for (int j=0; j<=1000; j++) ans = min(ans, dp[(1<<N)-1][j]);
    cout << dp[(1<<N) - 1][sum%MOD] << endl;
} 
0