結果

問題 No.332 数列をプレゼントに
ユーザー o.O~?
提出日時 2024-10-03 15:21:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 172,312 KB
実行使用メモリ 25,244 KB
最終ジャッジ日時 2024-10-03 15:21:21
合計ジャッジ時間 3,484 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const int MAXN = 111;
const int MAX = 50000;
pii A[MAXN];
int dp[MAXN*MAX];
bool use[MAXN];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
ll X;
cin >> N >> X;
for (int i = 0; i < N; i++) {
cin >> A[i].first;
A[i].second = i;
}
sort(A, A+N);
int cnt = 0;
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (; cnt < N && A[cnt].first < MAX; 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 rest = N-cnt;
for (int s = 0; s < 1<<rest; s++) {
ll sum = 0;
for (int i = 0; i < rest; i++) {
if ((s>>i)&1) sum += A[cnt+i].first;
}
ll tar = X - sum;
if (0 <= tar && tar < MAXN * MAX && dp[tar] != -1)
{
for (int i = 0; i < rest; 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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0