結果
| 問題 |
No.1597 Matrix Sort
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:05:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,399 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 81,472 KB |
| 実行使用メモリ | 116,008 KB |
| 最終ジャッジ日時 | 2025-04-16 00:07:35 |
| 合計ジャッジ時間 | 30,116 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 TLE * 10 |
ソースコード
import bisect
def find_kth_smallest():
import sys
input = sys.stdin.read().split()
idx = 0
N = int(input[idx]); idx +=1
K = int(input[idx]); idx +=1
P = int(input[idx]); idx +=1
A = list(map(int, input[idx:idx+N]))
idx +=N
B = list(map(int, input[idx:idx+N]))
idx +=N
B.sort()
low = 0
high = P - 1
ans = P - 1
while low <= high:
mid = (low + high) // 2
total = 0
for a in A:
# Case 1: B_j <= mid - a (if mid >= a)
if mid >= a:
target = mid - a
case1 = bisect.bisect_right(B, target)
else:
case1 = 0
# Case 2: B_j in [P - a, mid + P - a] (clamped to P-1)
lower = P - a
upper = mid + P - a
upper = min(upper, P - 1)
if lower > upper:
case2 = 0
else:
left = bisect.bisect_left(B, lower)
right = bisect.bisect_right(B, upper)
case2 = right - left
total += case1 + case2
if total > K * 2: # Early exit if possible to avoid overflow
break
if total >= K:
ans = mid
high = mid - 1
else:
low = mid + 1
print(ans)
find_kth_smallest()
lam6er