結果

問題 No.286 Modulo Discount Store
ユーザー nn1k_nn1k_
提出日時 2019-03-12 19:52:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,629 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 101,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 20:23:44
合計ジャッジ時間 2,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <limits>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_map>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <stack>
#include <string>
#include <functional>
using namespace std;

using i64 = long long int;
using ui64 = unsigned long long int;

using P = pair<int, int>;

constexpr int INF = (1 << 30);
constexpr i64 INF64 = (1LL << 60);
constexpr int MOD = 1000000000 + 7;

int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

template <typename T, typename U>
static inline std::vector<U> makeNdVector(T n, U val) noexcept {
   static_assert(std::is_integral<T>::value, "[makeNdVector] 1st argument must be an integer type");
   return std::vector<U>(std::forward<T>(n), std::forward<U>(val));
}

template <typename T, typename ...Args>
static inline decltype(auto) makeNdVector(T n, Args... args) noexcept {
   static_assert(std::is_integral<T>::value, "[makeNdVector] 1st argument must be an integer type");
   return std::vector<decltype(makeNdVector(std::forward<Args>(args)...))>(std::forward<T>(n), makeNdVector(std::forward<Args>(args)...));
}

template <typename T>
void print(vector<T> vec)
{
   for (auto &e : vec)
      cout << e << " ";
   cout << endl;
}

template <typename T>
T gcd(T x, T y) {
   if (x == 0 || y == 0) return 0;
   T r;
   while ((r = x % y) != 0) {
      x = y;
      y = r;
   }
   return y;
}

template <typename T>
T lcm(T x, T y) {
   if (x == 0 || y == 0) return 0;
   return (x / gcd(x, y) * y);
}

int next_combination(int sub)
{
   int x = sub & -sub, y = sub + x;
   return (((sub & ~y) / x) >> 1) | y;
}

std::uint64_t combination(int n, int r) {
   if (n < 0 || r < 0) return 0;
   if (n < r) return 0;
   std::uint64_t k = 1;
   for (std::uint64_t d = 1; d <= r; ++d) {
      k *= n--;
      k /= d;
   }
   return k;
}

bool check(string str) {
	for (int i = 0; i < str.length() / 2; ++i) {
		if (str[i] != str[str.length() - 1 - i]) {
			return false;
		}
	}
	return true;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	using P = pair<i64, i64>;

	int N; cin >> N;
	vector<i64> M(N);
	for (int i = 0; i < N; ++i) cin >> M[i];

	vector<i64> dp(1 << N, INF);
	dp[0] = 0;
	for (int i = 0; i < (1 << N); ++i) {
		i64 sum = 0;
		for (int j = 0; j < N; ++j) {
			if ((i&(1 << j))) sum += M[j];
		}
		sum %= 1000;
		for (int j = 0; j < N; ++j) {
			if ((i&(1 << j)) == 0) {
				i64 cost = M[j] - sum;
				if (cost < 0) cost = 0;
				dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + cost);
			}
		}
	}

	cout << dp[(1 << N) - 1] << endl;
}
0