結果
| 問題 | No.332 数列をプレゼントに |
| コンテスト | |
| ユーザー |
uenoku
|
| 提出日時 | 2017-02-10 01:08:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,562 bytes |
| 記録 | |
| コンパイル時間 | 1,488 ms |
| コンパイル使用メモリ | 100,244 KB |
| 実行使用メモリ | 8,832 KB |
| 最終ジャッジ日時 | 2024-12-26 02:42:37 |
| 合計ジャッジ時間 | 20,074 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 24 WA * 18 |
ソースコード
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
const int M = 2000005;
pair<bool, int> dp[M] = {};
int main()
{
lli n, x;
lli a[105], b[105];
vector<lli> big, small, bigm, smallm;
cin >> n >> x;
rep(i, n)
{
cin >> a[i];
if (a[i] > 20000) {
big.push_back(a[i]);
bigm.push_back(i);
} else {
small.push_back(a[i]);
smallm.push_back(i);
}
}
if (small.size() > 0) {
dp[small[0]] = make_pair(true, 0);
}
for (int i = 1; i < small.size(); i++) {
dp[small[i]] = make_pair(true, i);
rrep(j, M)
{
if (dp[j].first && j + small[i] < M && !dp[j + small[i]].first)
dp[j + small[i]] = make_pair(true, i);
}
}
set<lli> l;
rep(j, M) if (dp[j].first) l.insert(j);
map<lli, lli> memo;
set<lli> s;
for (lli i = 0; i < (1 << big.size()); i++) {
lli temp = i;
lli sum = 0;
rep(j, big.size())
{
if ((temp >> j) & 1)
sum += big[j];
}
//cout << sum << endl;
memo[sum] = i;
s.insert(sum);
}
s.insert(0);
l.insert(0);
for (auto j : s) {
for (auto i : l) {
if (j + i == x) {
//cout << i << endl;
lli re = memo[j];
bool flag[105] = {};
rep(k, big.size())
{
if ((re >> k) & 1) {
flag[bigm[k]] = true;
}
}
lli cnt = dp[i].second;
if (i > 0) {
while (1) {
flag[smallm[cnt]] = true;
if (i == 0)
break;
i -= small[dp[i].second];
cnt = dp[i].second;
}
}
cnt = 0;
rep(k, n)
{
if (flag[k]) {
cout << "o";
cnt += a[k];
} else
cout << "x";
}
cout << endl;
return 0;
}
}
}
cout << "No" << endl;
}
uenoku