結果

問題 No.941 商とあまり
ユーザー QCFiumQCFium
提出日時 2019-11-04 09:56:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,226 bytes
コンパイル時間 3,429 ms
コンパイル使用メモリ 193,716 KB
実行使用メモリ 27,848 KB
最終ジャッジ日時 2023-10-13 01:54:35
合計ジャッジ時間 19,194 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
9,656 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 18 ms
4,348 KB
testcase_08 AC 18 ms
4,376 KB
testcase_09 AC 17 ms
4,620 KB
testcase_10 AC 54 ms
4,816 KB
testcase_11 AC 29 ms
4,684 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 48 ms
5,240 KB
testcase_14 AC 23 ms
4,860 KB
testcase_15 AC 73 ms
5,304 KB
testcase_16 AC 118 ms
5,960 KB
testcase_17 AC 138 ms
6,140 KB
testcase_18 AC 354 ms
7,924 KB
testcase_19 AC 1,110 ms
12,752 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,480 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 54 ms
4,876 KB
testcase_27 AC 69 ms
5,296 KB
testcase_28 AC 21 ms
4,864 KB
testcase_29 AC 164 ms
6,208 KB
testcase_30 AC 164 ms
6,144 KB
testcase_31 AC 19 ms
4,632 KB
testcase_32 AC 6 ms
4,352 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 359 ms
7,972 KB
testcase_35 AC 288 ms
7,584 KB
testcase_36 AC 18 ms
4,564 KB
testcase_37 AC 18 ms
4,440 KB
testcase_38 AC 17 ms
4,764 KB
testcase_39 AC 19 ms
4,688 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 17 ms
4,380 KB
testcase_44 AC 17 ms
4,692 KB
testcase_45 AC 1,244 ms
11,536 KB
testcase_46 AC 497 ms
7,736 KB
testcase_47 AC 17 ms
4,936 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 53 ms
5,148 KB
testcase_50 AC 29 ms
4,808 KB
testcase_51 AC 36 ms
4,880 KB
testcase_52 AC 23 ms
4,576 KB
testcase_53 AC 29 ms
4,804 KB
testcase_54 AC 1,375 ms
12,584 KB
testcase_55 AC 1,376 ms
12,500 KB
testcase_56 AC 1,348 ms
12,540 KB
testcase_57 TLE -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
testcase_107 -- -
testcase_108 -- -
testcase_109 -- -
権限があれば一括ダウンロードができます

ソースコード

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');
	}
	
	std::map<int, int> nums;
	for (auto i : a) nums[i]++;
	std::vector<std::pair<int, int> > all;
	for (auto i : nums) all.push_back(i);
	std::map<std::vector<int>, std::vector<bool> > dp;
	int m = nums.size();
	for (int i = 0; i < m; i++) {
		std::vector<int> num(all.size());
		num[i] = 1;
		int size = x + 1;
		for (int j = 0; j < m; j++) for (int k = 0; k < all[j].second - num[j]; k++) size /= all[j].first;
		std::vector<bool> val(size);
		assert(all[i].first < size);
		val[all[i].first] = true;
		dp[num] = val;
	}
	for (auto &i : dp) {
		for (int j = 0; j < m; j++) {
			if (i.first[j] == all[j].second) continue;
			auto new_num = i.first;
			new_num[j]++;
			int new_size = x + 1;
			std::vector<bool> new_val(new_size);
			for (int k = 1; k < (int) i.second.size(); k++) {
				if (!i.second[k]) continue;
				int64_t target = (int64_t) (k + 1) * (all[j].first + 1) - 1;
				if (target < new_size) new_val[target] = true;
			}
			for (int k = 0; k < new_size - all[j].first; k++) if (new_val[k]) new_val[k + all[j].first] = true;
			auto &res = dp[new_num];
			if (!res.size()) res = new_val;
			else for (int k = 0; k < new_size; k++) if (new_val[k]) res[k] = true;
		}
	}
	std::vector<int> final(m);
	for (int i = 0; i < m; i++) final[i] = all[i].second;
	assert(dp.count(final));
	auto res = dp[final];
	assert((int) res.size() == x + 1);
	std::string ans;
	for (int i = 1; i <= x; i++) ans.push_back(res[i] ? '1' : '0');
	return ans;
}

int main() {
	int n = ri(), x = ri();
	assert(1 <= n && n <= 100);
	assert(1 <= x && x <= 500000);
	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