結果

問題 No.332 数列をプレゼントに
ユーザー rpy3cpprpy3cpp
提出日時 2016-02-29 13:17:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,377 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 405,668 KB
最終ジャッジ日時 2023-10-24 19:08:21
合計ジャッジ時間 6,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
14,552 KB
testcase_01 AC 29 ms
10,204 KB
testcase_02 AC 29 ms
10,204 KB
testcase_03 AC 27 ms
10,204 KB
testcase_04 AC 27 ms
10,304 KB
testcase_05 AC 1,279 ms
154,244 KB
testcase_06 MLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, X = map(int, input().split())
    As = list(map(int, input().split()))
    return N, X, As


def solve(N, X, As):
    Bs = [(a, i) for i, a in enumerate(As)]
    Bs.sort()
    n_large = min(N, 20)
    n_small = N - n_large
    len_dp = sum(As[:n_small]) + 1
    dp_small = fill_dp(n_small, len_dp, Bs[:n_small])
    lst_large = brute_force(n_large, Bs[n_small:])
    for val, bits in lst_large:
        dif = X - val
        if dif == 0:
            return decode(bits, N)
        elif 0 < dif < len_dp and dp_small[dif]:
            return decode(bits + dp_small[dif], N)
    return "No"


def decode(bits, N):
    result = []
    for i in range(N):
        if bits & 1:
            result.append('o')
        else:
            result.append('x')
        bits >>= 1
    return ''.join(result)


def fill_dp(n, length, Bs):
    dp = [0] * length
    for val, idx in Bs:
        bit = 1 << idx
        for i in range(length - 1 - val, 0, -1):
            if dp[i]:
                dp[i + val] = dp[i] | bit
        dp[val] = bit
    return dp


def brute_force(n, Bs):
    lst = [(0, 0)] * (1 << n)
    length = 1
    for val, idx in Bs:
        bit = 1 << idx
        for i in range(length):
            v, mask = lst[i]
            lst[i + length] = (v + val, mask | bit)
        length <<= 1
    return lst


params = read_data()
print(solve(*params))
0