結果
| 問題 | 
                            No.286 Modulo Discount Store
                             | 
                    
| コンテスト | |
| ユーザー | 
                             syawacha
                         | 
                    
| 提出日時 | 2019-04-05 19:43:28 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 801 bytes | 
| コンパイル時間 | 815 ms | 
| コンパイル使用メモリ | 82,552 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-13 01:03:05 | 
| 合計ジャッジ時間 | 1,787 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
ソースコード
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const int inf  = 1000000000;
int main(){
  int N;
  cin >> N;
  int M[N];
  for(int i=0;i<N;i++) cin >> M[i];
  int dp[1<<N];
  int sum[1<<N] = {};
  fill(dp,dp+(1<<N),inf);
  dp[0] = 0;
  for(int msk=0;msk<(1<<N);msk++){
    for(int i=0;i<N;i++){
      if(!(msk & (1<<i))){
        int x; //商品iの値段
        x = max(0, M[i] - sum[msk] % 1000);
        //cout << x << endl;
        dp[msk + (1<<i)] = min((dp[msk + (1<<i)]), dp[msk] + x);
        sum[msk + (1<<i)] = sum[msk] + M[i];
      }
    }
  }
  cout << dp[(1<<N) - 1] << endl;
  return 0;
}
            
            
            
        
            
syawacha