結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:59:18 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,398 bytes |
コンパイル時間 | 491 ms |
コンパイル使用メモリ | 81,968 KB |
実行使用メモリ | 116,160 KB |
最終ジャッジ日時 | 2025-04-16 00:01:10 |
合計ジャッジ時間 | 7,643 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 TLE * 5 -- * 19 |
ソースコード
import bisect def find_kth_smallest(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 K = int(data[idx]) idx += 1 P = int(data[idx]) idx += 1 A = list(map(int, data[idx:idx+N])) idx += N B = list(map(int, data[idx:idx+N])) idx += N B.sort() low = 0 high = P - 1 answer = 0 while low <= high: mid = (low + high) // 2 total = 0 for x in A: # Case 1: y <= mid - x target_case1 = mid - x if target_case1 >= 0: cnt1 = bisect.bisect_right(B, target_case1) else: cnt1 = 0 # Case 2: y >= (P - x) and y <= min(mid + P - x, P-1) lower_case2 = P - x upper_case2 = mid + P - x if upper_case2 > P - 1: upper_case2 = P - 1 if lower_case2 > upper_case2: cnt2 = 0 else: left = bisect.bisect_left(B, lower_case2) right = bisect.bisect_right(B, upper_case2) cnt2 = right - left total += cnt1 + cnt2 if total >= K: answer = mid high = mid - 1 else: low = mid + 1 print(answer) find_kth_smallest()