結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2025-04-16 16:30:40 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,398 bytes |
コンパイル時間 | 804 ms |
コンパイル使用メモリ | 82,044 KB |
実行使用メモリ | 116,464 KB |
最終ジャッジ日時 | 2025-04-16 16:32:27 |
合計ジャッジ時間 | 8,401 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 TLE * 12 |
ソースコード
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()