結果

問題 No.286 Modulo Discount Store
ユーザー alpha_virginisalpha_virginis
提出日時 2015-10-09 22:57:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,285 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 146,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 10:14:34
合計ジャッジ時間 3,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 6 ms
4,376 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 6 ms
4,380 KB
testcase_32 AC 6 ms
4,376 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 6 ms
4,376 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 6 ms
4,376 KB
testcase_39 AC 7 ms
4,384 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 6 ms
4,380 KB
testcase_42 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

const unsigned long mod = 1000000007;
const double EPS = 0.00000001;
const int INF = (1 << 29);

typedef std::pair<int, int> pii;

template<typename T>
void print_array(T *A_, s32 size) {
  //printf("%d\n", size);
  if( size != 0 ) {
    for(int i = 0; i < size - 1; ++i) {
      printf("%d ", A_[i]);
    }
    printf("%d\n", A_[size - 1]);
  }
}

auto main() -> int {

  int n;
  std::vector<int> m;
  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    int temp;
    std::cin >> temp;
    m.push_back(temp);
  }

  int dp[65536];
  int total[65536];
  for(int i = 0; i < 65536; ++i) {
    int temp = 0;
    for(int j = 0; j < 16; ++j) {
      if( (i & (1 << j)) != 0 ) {
        temp += m[j];
      }
    }
    total[i] = temp;
  }

  for(int i = 0; i < 65536; ++i) {
    dp[i] = INF;
  }
  dp[0] = 0;

  for(int i = 0; i < (1 << n); ++i) {
    for(int j = 0; j < n; ++j) {
      if( (i & (1 << j)) == 0 ) {
        dp[i + (1 << j)] = std::min(dp[i + (1 << j)], dp[i] + std::max(0, m[j] - total[i] % 1000));
      }
    }
  }

  std::cout << dp[(1 << n) - 1] << std::endl;

  return 0;
}
0