結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:57:39 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,143 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 81,432 KB |
実行使用メモリ | 116,388 KB |
最終ジャッジ日時 | 2025-04-15 23:59:37 |
合計ジャッジ時間 | 26,705 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 TLE * 8 |
ソースコード
import bisect def main(): 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 ans = 0 while low <= high: mid = (low + high) // 2 total = 0 for a in A: L = (p - a) % p R = (mid - a) % p if L <= R: left = bisect.bisect_left(B, L) right = bisect.bisect_right(B, R) cnt = right - left else: cnt_high = len(B) - bisect.bisect_left(B, L) cnt_low = bisect.bisect_right(B, R) cnt = cnt_high + cnt_low total += cnt if total > k * 2: # Early exit if possible break if total >= k: ans = mid high = mid - 1 else: low = mid + 1 print(ans) if __name__ == "__main__": main()