結果
| 問題 | No.949 飲酒プログラミングコンテスト |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-09 01:23:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,051 bytes |
| 記録 | |
| コンパイル時間 | 323 ms |
| コンパイル使用メモリ | 82,648 KB |
| 実行使用メモリ | 335,216 KB |
| 最終ジャッジ日時 | 2025-12-09 01:23:46 |
| 合計ジャッジ時間 | 5,769 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 1 -- * 21 |
ソースコード
## https://yukicoder.me/problems/no/944
from collections import deque
def bisearch(N, D, f, low_index):
if low_index == N:
return N
if D[-1] > f:
return N
low = low_index
high = N - 1
while high - low > 1:
mid = (high + low) //2
if D[mid] <= f:
high = mid
else:
low = mid
if D[low] <= f:
return low
else:
return high
def main():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = list(map(int, input().split()))
D.sort(reverse=True)
queue = deque()
queue.append((0, 0))
min_d_index = {(0, 0): -1}
passed = [[False] * (N + 1) for _ in range(N + 1)]
while len(queue) > 0:
a_index, b_index = queue.popleft()
if passed[a_index][b_index]:
continue
passed[a_index][b_index] = True
d_index = min_d_index[(a_index, b_index)]
if d_index == N - 1:
continue
# a_index + 1する
new_a_index = a_index + 1
new_b_index = b_index
f = A[new_a_index] + B[new_b_index]
eat_index = bisearch(N, D, f, d_index + 1)
if eat_index < N:
key = (new_a_index, new_b_index)
if key not in min_d_index:
min_d_index[key] = 2 * N
min_d_index[key] = min(min_d_index[key], eat_index)
queue.append((new_a_index, new_b_index))
new_a_index = a_index
new_b_index = b_index + 1
f = A[new_a_index] + B[new_b_index]
eat_index = bisearch(N, D, f, d_index + 1)
if eat_index < N:
key = (new_a_index, new_b_index)
if key not in min_d_index:
min_d_index[key] = 2 * N
min_d_index[key] = min(min_d_index[key], eat_index)
queue.append((new_a_index, new_b_index))
answer = 0
for a, b in min_d_index.keys():
answer = max(answer, a + b)
print(answer)
if __name__ == "__main__":
main()