結果
| 問題 | No.332 数列をプレゼントに |
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-04-15 01:18:12 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 562 ms / 2,000 ms |
| コード長 | 1,281 bytes |
| コンパイル時間 | 278 ms |
| コンパイル使用メモリ | 13,056 KB |
| 実行使用メモリ | 77,480 KB |
| 最終ジャッジ日時 | 2024-10-01 18:32:38 |
| 合計ジャッジ時間 | 23,620 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 42 |
ソースコード
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N, X = map(int, readline().split())
A = list(map(int, read().split()))
K = 10 ** 5
low = []
high = []
for x in A:
if x <= K:
low.append(x)
else:
high.append(x)
low.sort()
L = len(low)
H = len(high)
dpl = [None] * (L + 1)
dpl[0] = np.zeros(1, np.int64)
for i, x in enumerate(low, 1):
dp = np.full(len(dpl[i - 1]) + x, -1, np.int32)
dp[:-x] = dpl[i - 1]
dp[x:][dpl[i - 1] >= 0] = i
dpl[i] = dp
dph = np.zeros(1 << H, np.int64)
for i, x in enumerate(high):
dph[1 << i: 1 << i + 1] = dph[: 1 << i] + x
nums = X - dph
nums = nums[(0 <= nums) & (nums < len(dpl[-1]))]
nums = nums[dpl[-1][nums] >= 0]
if not len(nums):
print('No')
exit()
low_sum = nums[0]
high_sum = X - low_sum
# 復元
low_ind = []
high_ind = []
n = len(low)
while low_sum:
n = dpl[n][low_sum] - 1
low_sum -= low[n]
low_ind.append(n)
i = np.where(dph == high_sum)[0][0]
for j in range(H):
if i & (1 << j):
high_ind.append(j)
nums = [low[i] for i in low_ind] + [high[i] for i in high_ind]
for x in nums:
i = A.index(x)
A[i] = 0
answer = ''.join('x' if x else 'o' for x in A)
print(answer)
maspy