結果
| 問題 |
No.332 数列をプレゼントに
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-03 20:18:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 2,000 ms |
| コード長 | 1,561 bytes |
| コンパイル時間 | 1,843 ms |
| コンパイル使用メモリ | 171,256 KB |
| 実行使用メモリ | 124,772 KB |
| 最終ジャッジ日時 | 2024-10-03 20:18:54 |
| 合計ジャッジ時間 | 5,455 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 42 |
ソースコード
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> P;
const int N = 310;
const int M = 50010;
P A[N];
ll n, t, cnt = 0, dp[N * M];
bool use[N];
int main()
{
scanf("%lld%lld", &n, &t);
for (int i = 0; i < n; i++)
{
scanf("%lld", &A[i].first);
A[i].second = i;
}
sort(A, A + n);
memset(dp, -1, sizeof(dp));
dp[0] = 0;
while (cnt < n && A[cnt].first < M) cnt++;
for (int i = 0; i < cnt; i++)
{
for (int j = (i + 1) * A[i].first; j >= A[i].first; j--)
{
if (dp[j] != -1) continue;
if (dp[j - A[i].first] == -1) continue;
dp[j] = i;
}
}
int res = n -cnt;
for (int s = 0; s < (1 << res); s++)
{
ll sum = 0;
for (int i = 0; i < res; i++)
{
if ((s >> i) & 1) sum += A[cnt + i].first;
}
ll tar = t - sum;
if (0 <= tar && tar < n * M && dp[tar] != -1)
{
for (int i = 0; i < res; i++)
{
if ((s >> i) & 1) use[A[i + cnt].second] = true;
}
ll now;
now = tar;
while (now != 0)
{
use[A[dp[now]].second] = true;
now -= A[dp[now]].first;
}
for (int i = 0; i < n; i++)
{
if (use[i]) cout << "o";
else cout << "x";
}
cout << endl;
return 0;
}
}
cout << "No\n";
return 0;
}