結果

問題 No.286 Modulo Discount Store
ユーザー kyo1
提出日時 2020-06-04 05:29:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 2,688 ms
コンパイル使用メモリ 193,828 KB
最終ジャッジ日時 2025-01-10 20:57:41
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> M(N);
  for (int i = 0; i < N; i++) {
    cin >> M[i];
  }
  vector<int> dp(1 << N, INF);
  dp[0] = 0;
  for (int b = 0; b < (1 << N); b++) {
    int sum = 0;
    for (int i = 0; i < N; i++) {
      if ((b >> i) & 1) sum += M[i];
    }
    for (int i = 0; i < N; i++) {
      if (((b >> i) & 1) == 0)
        chmin(dp[b | (1 << i)], dp[b] + max(0, M[i] - (sum % 1000)));
    }
  }
  cout << dp[(1 << N) - 1] << '\n';
  return 0;
}
0