結果
問題 | No.332 数列をプレゼントに |
ユーザー | rpy3cpp |
提出日時 | 2016-02-29 13:30:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 775 ms / 2,000 ms |
コード長 | 1,395 bytes |
コンパイル時間 | 112 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 182,400 KB |
最終ジャッジ日時 | 2024-12-24 08:35:46 |
合計ジャッジ時間 | 26,163 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
10,624 KB |
testcase_01 | AC | 34 ms
10,752 KB |
testcase_02 | AC | 34 ms
10,752 KB |
testcase_03 | AC | 33 ms
10,752 KB |
testcase_04 | AC | 33 ms
10,752 KB |
testcase_05 | AC | 505 ms
150,400 KB |
testcase_06 | AC | 511 ms
164,736 KB |
testcase_07 | AC | 624 ms
164,736 KB |
testcase_08 | AC | 517 ms
165,760 KB |
testcase_09 | AC | 42 ms
12,800 KB |
testcase_10 | AC | 574 ms
150,400 KB |
testcase_11 | AC | 499 ms
150,528 KB |
testcase_12 | AC | 521 ms
166,784 KB |
testcase_13 | AC | 518 ms
165,760 KB |
testcase_14 | AC | 517 ms
150,400 KB |
testcase_15 | AC | 574 ms
167,040 KB |
testcase_16 | AC | 531 ms
166,656 KB |
testcase_17 | AC | 539 ms
176,896 KB |
testcase_18 | AC | 750 ms
166,400 KB |
testcase_19 | AC | 519 ms
166,784 KB |
testcase_20 | AC | 575 ms
166,016 KB |
testcase_21 | AC | 551 ms
166,528 KB |
testcase_22 | AC | 554 ms
166,016 KB |
testcase_23 | AC | 567 ms
166,400 KB |
testcase_24 | AC | 624 ms
166,272 KB |
testcase_25 | AC | 604 ms
166,656 KB |
testcase_26 | AC | 587 ms
166,784 KB |
testcase_27 | AC | 518 ms
166,784 KB |
testcase_28 | AC | 621 ms
166,784 KB |
testcase_29 | AC | 615 ms
166,912 KB |
testcase_30 | AC | 545 ms
166,784 KB |
testcase_31 | AC | 611 ms
166,784 KB |
testcase_32 | AC | 604 ms
166,912 KB |
testcase_33 | AC | 621 ms
166,784 KB |
testcase_34 | AC | 622 ms
166,656 KB |
testcase_35 | AC | 615 ms
164,736 KB |
testcase_36 | AC | 32 ms
10,752 KB |
testcase_37 | AC | 688 ms
182,272 KB |
testcase_38 | AC | 692 ms
182,400 KB |
testcase_39 | AC | 702 ms
182,272 KB |
testcase_40 | AC | 559 ms
133,888 KB |
testcase_41 | AC | 548 ms
133,888 KB |
testcase_42 | AC | 545 ms
134,144 KB |
testcase_43 | AC | 616 ms
150,400 KB |
testcase_44 | AC | 523 ms
155,648 KB |
testcase_45 | AC | 775 ms
167,168 KB |
testcase_46 | AC | 656 ms
150,400 KB |
ソースコード
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))