結果

問題 No.332 数列をプレゼントに
ユーザー maspy
提出日時 2020-03-24 14:49:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 766 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,376 KB
最終ジャッジ日時 2024-12-31 15:02:41
合計ジャッジ時間 9,627 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 40 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N, X, *A = map(int, read().split())
B = sorted(A)


def dfs(B, S, can_use_max=X + 1):
    if sum(B) < S:
        return False
    if sum(B) == S:
        return B.copy()
    x = B.pop()
    if x < S and x <= can_use_max:
        res = dfs(B, S - x)
        if res:
            return res + [x]
    res = dfs(B, S, x - 1)
    B.append(x)
    return res


C = dfs(B, X)
if C:
    C.sort()
    i = 0
    res = set(range(N))
    answer = ['x'] * N
    for c in C:
        for i in res:
            if A[i] == c:
                break
        res.remove(i)
        answer[i] = 'o'
    print(''.join(answer))
else:
    print('No')
0