結果
問題 |
No.332 数列をプレゼントに
|
ユーザー |
|
提出日時 | 2024-10-03 14:41:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,396 bytes |
コンパイル時間 | 1,734 ms |
コンパイル使用メモリ | 170,392 KB |
実行使用メモリ | 64,256 KB |
最終ジャッジ日時 | 2024-10-03 14:41:31 |
合計ジャッジ時間 | 7,866 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 WA * 1 |
other | AC * 31 WA * 11 |
ソースコード
# 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]; int n, t, cnt = 0, dp[N * M]; bool use[N]; int main() { scanf("%d%d", &n, &t); for (int i = 0; i < n; i++) { scanf("%d", &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 = tar; while (now != 0) { use[A[dp[now]].second] = true; now -= A[dp[now]].first; } for (int i = 0; i < n; i++) printf(use[i] ? "o" : "x"); printf("\n"); return 0; } } puts("No"); return 0; }