結果
| 問題 | 
                            No.286 Modulo Discount Store
                             | 
                    
| コンテスト | |
| ユーザー | 
                             latte0119
                         | 
                    
| 提出日時 | 2015-10-17 01:21:05 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 6 ms / 2,000 ms | 
| コード長 | 699 bytes | 
| コンパイル時間 | 2,418 ms | 
| コンパイル使用メモリ | 161,088 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-22 07:42:31 | 
| 合計ジャッジ時間 | 2,601 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
main.cpp:19:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |     rep(i,N)scanf("%d",&A[i]);
      |             ~~~~~^~~~~~~~~~~~
            
            ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
typedef vector<int>VI;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define maxv(a,b) (a)=max((a),(b))
#define minv(a,b) (a)=min((a),(b))
const int INF=1001001001;
int N;
VI A;
int dp[1<<16];
int main(){
    scanf("%d",&N);
    A.resize(N);
    rep(i,N)scanf("%d",&A[i]);
    fill_n(dp,1<<N,INF);
    dp[0]=0;
    rep(i,1<<N){
        int sum=0;
        rep(j,N)if(i>>j&1)sum+=A[j];
        sum%=1000;
        rep(j,N){
            if(i>>j&1)continue;
            minv(dp[i|(1<<j)],dp[i]+max(0,A[j]-sum));
        }
    }
    printf("%d\n",dp[(1<<N)-1]);
    return 0;
}
            
            
            
        
            
latte0119