結果
| 問題 |
No.332 数列をプレゼントに
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:38:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,484 bytes |
| コンパイル時間 | 204 ms |
| コンパイル使用メモリ | 82,608 KB |
| 実行使用メモリ | 53,464 KB |
| 最終ジャッジ日時 | 2025-06-12 19:38:11 |
| 合計ジャッジ時間 | 4,822 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | TLE * 1 -- * 41 |
ソースコード
import sys
sys.setrecursionlimit(1000000)
def main():
import sys
N, X = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
def solve():
total = sum(A)
if total < X:
return "No"
if total == X:
return "o" * N
target = total - X
if target == 0:
return "o" * N
A_sorted = sorted(A, reverse=True)
selected = [False] * N
from itertools import combinations
for k in range(1, len(A_sorted)+1):
for indices in combinations(range(len(A_sorted)), k):
s = sum(A_sorted[i] for i in indices)
if s == target:
selected_indices = set(indices)
selected = [False] * N
for i in range(len(A_sorted)):
if i in selected_indices:
original_index = A.index(A_sorted[i]) if A_sorted[i] in A else -1
if original_index == -1 or selected[original_index]:
continue
selected[original_index] = True
for i in range(len(A_sorted)):
if i in selected_indices:
j = i
while j < len(A_sorted) and A_sorted[j] == A_sorted[i]:
j += 1
for k in range(i, j):
original_index = A.index(A_sorted[k])
if not selected[original_index]:
selected[original_index] = True
break
break
if any(selected):
break
if any(selected):
s = sum(A[i] for i in range(N) if selected[i])
if s == target:
s_complement = sum(A[i] for i in range(N) if not selected[i])
if s_complement == X:
res = ['x'] * N
for i in range(N):
if not selected[i]:
res[i] = 'o'
return ''.join(res)
else:
return "No"
else:
return "No"
else:
return "No"
result = solve()
print(result)
if __name__ == "__main__":
main()
gew1fw