結果
| 問題 |
No.941 商とあまり
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2019-11-04 09:56:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,226 bytes |
| コンパイル時間 | 2,542 ms |
| コンパイル使用メモリ | 197,116 KB |
| 実行使用メモリ | 28,672 KB |
| 最終ジャッジ日時 | 2024-09-14 23:38:38 |
| 合計ジャッジ時間 | 17,723 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 6 |
| other | AC * 57 TLE * 1 -- * 46 |
ソースコード
#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;
}
QCFium