結果

問題 No.332 数列をプレゼントに
ユーザー rpy3cpprpy3cpp
提出日時 2016-02-29 13:30:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 557 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 180,044 KB
最終ジャッジ日時 2023-08-25 21:53:48
合計ジャッジ時間 19,909 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,380 KB
testcase_01 AC 14 ms
8,248 KB
testcase_02 AC 14 ms
8,364 KB
testcase_03 AC 14 ms
8,248 KB
testcase_04 AC 15 ms
8,544 KB
testcase_05 AC 345 ms
148,104 KB
testcase_06 AC 347 ms
162,180 KB
testcase_07 AC 427 ms
162,364 KB
testcase_08 AC 356 ms
163,240 KB
testcase_09 AC 20 ms
10,440 KB
testcase_10 AC 396 ms
147,992 KB
testcase_11 AC 347 ms
148,048 KB
testcase_12 AC 354 ms
164,356 KB
testcase_13 AC 355 ms
163,364 KB
testcase_14 AC 337 ms
148,032 KB
testcase_15 AC 411 ms
164,408 KB
testcase_16 AC 381 ms
164,100 KB
testcase_17 AC 398 ms
174,336 KB
testcase_18 AC 557 ms
163,928 KB
testcase_19 AC 386 ms
164,308 KB
testcase_20 AC 391 ms
163,644 KB
testcase_21 AC 366 ms
164,036 KB
testcase_22 AC 376 ms
163,676 KB
testcase_23 AC 384 ms
163,756 KB
testcase_24 AC 418 ms
163,752 KB
testcase_25 AC 419 ms
164,204 KB
testcase_26 AC 403 ms
164,304 KB
testcase_27 AC 348 ms
164,308 KB
testcase_28 AC 412 ms
164,448 KB
testcase_29 AC 414 ms
164,296 KB
testcase_30 AC 359 ms
164,444 KB
testcase_31 AC 416 ms
164,308 KB
testcase_32 AC 411 ms
164,300 KB
testcase_33 AC 422 ms
164,292 KB
testcase_34 AC 427 ms
164,156 KB
testcase_35 AC 424 ms
162,244 KB
testcase_36 AC 14 ms
8,240 KB
testcase_37 AC 475 ms
180,044 KB
testcase_38 AC 485 ms
179,876 KB
testcase_39 AC 466 ms
180,016 KB
testcase_40 AC 391 ms
131,316 KB
testcase_41 AC 377 ms
131,304 KB
testcase_42 AC 390 ms
131,444 KB
testcase_43 AC 425 ms
148,096 KB
testcase_44 AC 340 ms
153,212 KB
testcase_45 AC 536 ms
164,616 KB
testcase_46 AC 440 ms
148,048 KB
権限があれば一括ダウンロードができます

ソースコード

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()
    As.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


N, X, As = read_data()
print(solve(N, X, As))
0