結果
問題 | No.2370 He ate many cakes |
ユーザー | LyricalMaestro |
提出日時 | 2024-01-22 01:27:58 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,651 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 77,220 KB |
最終ジャッジ日時 | 2024-01-22 01:28:02 |
合計ジャッジ時間 | 3,179 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,460 KB |
testcase_01 | AC | 40 ms
53,460 KB |
testcase_02 | AC | 36 ms
53,460 KB |
testcase_03 | AC | 124 ms
77,220 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 36 ms
53,460 KB |
testcase_07 | AC | 33 ms
53,460 KB |
testcase_08 | AC | 35 ms
53,460 KB |
testcase_09 | AC | 36 ms
53,460 KB |
testcase_10 | AC | 88 ms
76,888 KB |
testcase_11 | AC | 93 ms
77,220 KB |
testcase_12 | AC | 113 ms
76,888 KB |
testcase_13 | AC | 96 ms
77,220 KB |
testcase_14 | AC | 113 ms
77,220 KB |
testcase_15 | AC | 114 ms
77,220 KB |
testcase_16 | AC | 104 ms
77,016 KB |
testcase_17 | AC | 105 ms
77,220 KB |
testcase_18 | AC | 56 ms
66,276 KB |
testcase_19 | AC | 53 ms
66,276 KB |
ソースコード
## https://yukicoder.me/problems/no/2370 def solve(n1_array, n2_array, border): ans = 0 for n2 in n2_array: if border - n2 > n1_array[-1]: continue low = 0 high = len(n1_array) - 1 while high - low > 1: mid = (high + low) // 2 if n1_array[mid] >= border - n2: high = mid else: low = mid if n1_array[low] >= border - n2: ans += len(n1_array) - low else: ans += len(n1_array) - high return ans def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) if N == 1: array = [0, A[0]] array.sort() print(array[K - 1]) return # 半分全列挙 N1 = N // 2 N2 = N - N1 n1_array = [] for bit in range(2 ** N1): ans = 0 for i in range(N1): if bit & (1 << i) > 0: ans += A[i] n1_array.append(ans) n1_array.sort() n2_array = [] for bit in range(2 ** N2): ans = 0 for i in range(N2): if bit & (1 << i) > 0: ans += A[i + N1] n2_array.append(ans) # 二部探索によって値を出す low = sum([a for a in A if a < 0]) high = sum([a for a in A if a > 0]) while high - low > 1: mid = (high + low) // 2 if solve(n1_array, n2_array, mid) >= K: low = mid else: high = mid if solve(n1_array, n2_array, high) >= K: print(high) else: print(low) if __name__ == "__main__": main()