結果
| 問題 |
No.332 数列をプレゼントに
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:07:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 923 bytes |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 82,720 KB |
| 実行使用メモリ | 848,392 KB |
| 最終ジャッジ日時 | 2025-06-12 14:08:07 |
| 合計ジャッジ時間 | 4,039 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 2 MLE * 1 -- * 39 |
ソースコード
n, x = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
if total < x:
print("No")
elif total == x:
print('o' * n)
else:
# Initialize DP list to track possible sums at each step
dp = [set() for _ in range(n + 1)]
dp[0].add(0)
for i in range(n):
current = a[i]
dp[i+1] = dp[i].copy()
for s in dp[i]:
if s + current <= x:
dp[i+1].add(s + current)
if x not in dp[n]:
print("No")
else:
selected = set()
remaining = x
# Backtrack to find selected elements
for i in reversed(range(n)):
num = a[i]
if remaining >= num and (remaining - num) in dp[i]:
selected.add(i)
remaining -= num
# Generate the result string
result = ['o' if i in selected else 'x' for i in range(n)]
print(''.join(result))
gew1fw