結果

問題 No.941 商とあまり
ユーザー QCFiumQCFium
提出日時 2019-09-15 14:12:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,868 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 181,684 KB
実行使用メモリ 6,008 KB
最終ジャッジ日時 2023-08-18 11:54:58
合計ジャッジ時間 14,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
4,588 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 14 ms
4,384 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 26 ms
4,608 KB
testcase_11 AC 24 ms
4,612 KB
testcase_12 AC 19 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 353 ms
6,008 KB
testcase_15 AC 403 ms
5,700 KB
testcase_16 AC 399 ms
5,700 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 43 ms
4,444 KB
testcase_27 AC 63 ms
4,588 KB
testcase_28 AC 260 ms
5,256 KB
testcase_29 AC 323 ms
5,352 KB
testcase_30 AC 330 ms
5,396 KB
testcase_31 AC 187 ms
4,968 KB
testcase_32 AC 8 ms
4,384 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 23 ms
4,448 KB
testcase_37 AC 27 ms
4,380 KB
testcase_38 AC 23 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 103 ms
4,752 KB
testcase_46 AC 74 ms
4,764 KB
testcase_47 AC 172 ms
4,952 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 188 ms
4,984 KB
testcase_50 AC 46 ms
4,632 KB
testcase_51 AC 71 ms
4,736 KB
testcase_52 AC 31 ms
4,512 KB
testcase_53 AC 48 ms
4,500 KB
testcase_54 AC 149 ms
4,776 KB
testcase_55 AC 146 ms
4,900 KB
testcase_56 AC 142 ms
4,776 KB
testcase_57 AC 3 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 15 ms
4,376 KB
testcase_60 AC 15 ms
4,416 KB
testcase_61 AC 13 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 29 ms
4,656 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 28 ms
4,376 KB
testcase_69 AC 3 ms
4,380 KB
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 45 ms
4,380 KB
testcase_72 AC 46 ms
4,532 KB
testcase_73 AC 3 ms
4,380 KB
testcase_74 AC 2 ms
4,376 KB
testcase_75 AC 2 ms
4,376 KB
testcase_76 AC 3 ms
4,376 KB
testcase_77 AC 3 ms
4,376 KB
testcase_78 AC 2 ms
4,376 KB
testcase_79 AC 3 ms
4,376 KB
testcase_80 AC 2 ms
4,376 KB
testcase_81 AC 2 ms
4,376 KB
testcase_82 AC 2 ms
4,376 KB
testcase_83 AC 2 ms
4,380 KB
testcase_84 AC 2 ms
4,380 KB
testcase_85 AC 2 ms
4,380 KB
testcase_86 AC 2 ms
4,380 KB
testcase_87 AC 2 ms
4,376 KB
testcase_88 AC 3 ms
4,380 KB
testcase_89 AC 2 ms
4,380 KB
testcase_90 AC 2 ms
4,376 KB
testcase_91 AC 3 ms
4,376 KB
testcase_92 AC 2 ms
4,380 KB
testcase_93 AC 2 ms
4,380 KB
testcase_94 AC 2 ms
4,380 KB
testcase_95 AC 2 ms
4,380 KB
testcase_96 AC 2 ms
4,380 KB
testcase_97 AC 3 ms
4,376 KB
testcase_98 AC 2 ms
4,380 KB
testcase_99 AC 2 ms
4,376 KB
testcase_100 AC 3 ms
4,376 KB
testcase_101 AC 2 ms
4,380 KB
testcase_102 AC 3 ms
4,376 KB
testcase_103 AC 3 ms
4,380 KB
testcase_104 AC 2 ms
4,380 KB
testcase_105 AC 1 ms
4,376 KB
testcase_106 AC 2 ms
4,376 KB
testcase_107 AC 2 ms
4,376 KB
testcase_108 AC 1 ms
4,376 KB
testcase_109 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::string solve(int n, int x, const std::vector<int> &a_) {
	auto a = a_;
	if (n == 1) {
		std::string s(x, '0');
		if (a[0] <= x) s[a[0] - 1] = '1';
		return s;
	}
	std::sort(a.begin(), a.end());
	int64_t prod = 1;
	for (int i = 0; i < n; i++) {
		prod *= a[i] + 1;
		if (prod > x + 1) return std::string(x, '0');
	}
	if (std::count(a.begin(), a.end(), 1)) {
		std::string res(x, '0');
		for (int i = prod - 1; i <= x; i++) res[i - 1] = '1';
		return res;
	}
	std::vector<int> size(n + 1); // x / 3^i
	size[n] = x + 1;
	for (int i = n - 1; i >= 0; i--) size[i] = size[i + 1] / 3;
	
	std::vector<std::vector<bool> > dp(1 << n);
	for (int i = 0; i < 1 << n; i++) dp[i].resize(size[__builtin_popcount(i)]);
	for (int i = 0; i < n; i++) assert(a[i] < (int) dp[1 << i].size()), dp[1 << i][a[i]] = true;
	for (int i = 0; i < 1 << n; i++) {
		int cur_sz = dp[i].size();
		for (int j = 0; j < n; j++) {
			if (i >> j & 1) continue;
			std::vector<bool> tmp(dp[i | 1 << j].size());
			for (int k = 0; k < cur_sz; k++) {
				int target = (k + 1) * (a[j] + 1) - 1;
				if (dp[i][k] && target < (int) tmp.size()) tmp[target] = true;
			}
			for (int k = 0; k < (int) tmp.size() - a[j]; k++) if (tmp[k]) tmp[k + a[j]] = true;
			for (int k = 0; k < (int) tmp.size(); k++) if (tmp[k]) dp[i | 1 << j][k] = true;
		}
	}
	std::string res;
	for (int i = 1; i <= x; i++) res.push_back(dp.back()[i] ? '1' : '0');
	return res;
}

int main() {
	int n = ri(), x = ri();
	assert(1 <= n && n <= 100);
	assert(1 <= x && x <= 1000000);
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) a[i] = ri(), assert(1 <= a[i] && a[i] <= x);
	clock_t r0 = clock();
	std::cout << solve(n, x, a) << std::endl;
	clock_t r1 = clock();
	std::cerr << (double)(r1 - r0) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
	return 0;
}

0