結果

問題 No.286 Modulo Discount Store
ユーザー Lay_ecLay_ec
提出日時 2015-10-09 22:50:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 79,588 KB
実行使用メモリ 260,480 KB
最終ジャッジ日時 2023-09-27 10:14:23
合計ジャッジ時間 3,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
5,160 KB
testcase_02 AC 65 ms
67,700 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 128 ms
131,592 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 32 ms
35,240 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 64 ms
67,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
5,124 KB
testcase_17 AC 250 ms
260,480 KB
testcase_18 AC 32 ms
35,192 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 9 ms
10,940 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 65 ms
67,440 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 16 ms
19,088 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 18 ms
19,132 KB
testcase_28 AC 128 ms
131,656 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 5 ms
6,972 KB
testcase_32 AC 5 ms
6,996 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 4 ms
5,192 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 17 ms
19,136 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 131 ms
131,580 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

long long inf=1000000000;

int main()
{

    int n;
    cin>>n;
    
    vector<long long> p(n);
    for(int i=0;i<n;i++) cin>>p[i];
    
    vector<vector<long long> > dp(1<<n,vector<long long>(1000,inf));

    dp[0][0]=0;
    
    for(int bit=0;bit<(1<<n);bit++){
        for(long long i=0;i<1000;i++){
            if(dp[bit][i]==inf) continue;
            
            for(int j=0;j<n;j++){
                if(bit&(1<<j)) continue;
                int next=bit|(1<<j);
                //printf("(%lld,%lld)=%lld ->",bit,i,dp[bit][i]);
                dp[next][(i+p[j])%1000]=min(dp[next][(i+p[j])%1000],dp[bit][i]+max(0LL,p[j]-i));
                //printf("(%lld,%lld)=%lld\n",next,(i+p[j])%1000,dp[next][(i+p[j])%1000]);
            }
        }
    }
    
    long long res=dp[(1<<n)-1][0];
    for(int i=1;i<1000;i++) res=min(res,dp[(1<<n)-1][i]);
    cout<<res<<endl;

    return 0;
}
0