結果
問題 | No.332 数列をプレゼントに |
ユーザー | rpy3cpp |
提出日時 | 2016-02-29 13:30:51 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 668 ms / 2,000 ms |
コード長 | 1,395 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 182,504 KB |
最終ジャッジ日時 | 2024-06-06 16:19:07 |
合計ジャッジ時間 | 22,408 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,752 KB |
testcase_01 | AC | 29 ms
10,880 KB |
testcase_02 | AC | 28 ms
10,880 KB |
testcase_03 | AC | 28 ms
10,752 KB |
testcase_04 | AC | 27 ms
10,880 KB |
testcase_05 | AC | 448 ms
150,544 KB |
testcase_06 | AC | 453 ms
165,040 KB |
testcase_07 | AC | 538 ms
164,864 KB |
testcase_08 | AC | 452 ms
165,888 KB |
testcase_09 | AC | 35 ms
13,056 KB |
testcase_10 | AC | 506 ms
150,528 KB |
testcase_11 | AC | 437 ms
150,580 KB |
testcase_12 | AC | 459 ms
166,912 KB |
testcase_13 | AC | 457 ms
165,976 KB |
testcase_14 | AC | 437 ms
150,652 KB |
testcase_15 | AC | 487 ms
166,928 KB |
testcase_16 | AC | 454 ms
166,772 KB |
testcase_17 | AC | 469 ms
177,024 KB |
testcase_18 | AC | 648 ms
166,384 KB |
testcase_19 | AC | 445 ms
166,924 KB |
testcase_20 | AC | 502 ms
166,108 KB |
testcase_21 | AC | 467 ms
166,400 KB |
testcase_22 | AC | 481 ms
166,144 KB |
testcase_23 | AC | 496 ms
166,508 KB |
testcase_24 | AC | 543 ms
166,400 KB |
testcase_25 | AC | 544 ms
166,612 KB |
testcase_26 | AC | 516 ms
166,852 KB |
testcase_27 | AC | 470 ms
166,800 KB |
testcase_28 | AC | 532 ms
167,024 KB |
testcase_29 | AC | 528 ms
166,848 KB |
testcase_30 | AC | 469 ms
166,800 KB |
testcase_31 | AC | 533 ms
166,860 KB |
testcase_32 | AC | 538 ms
166,972 KB |
testcase_33 | AC | 536 ms
166,860 KB |
testcase_34 | AC | 531 ms
166,720 KB |
testcase_35 | AC | 544 ms
164,756 KB |
testcase_36 | AC | 27 ms
10,880 KB |
testcase_37 | AC | 619 ms
182,400 KB |
testcase_38 | AC | 621 ms
182,404 KB |
testcase_39 | AC | 604 ms
182,504 KB |
testcase_40 | AC | 492 ms
134,016 KB |
testcase_41 | AC | 483 ms
134,136 KB |
testcase_42 | AC | 475 ms
134,016 KB |
testcase_43 | AC | 531 ms
150,492 KB |
testcase_44 | AC | 449 ms
155,904 KB |
testcase_45 | AC | 668 ms
167,240 KB |
testcase_46 | AC | 552 ms
150,540 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))