結果
| 問題 | No.1597 Matrix Sort |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-20 16:52:00 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 625 bytes |
| 記録 | |
| コンパイル時間 | 238 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 193,920 KB |
| 最終ジャッジ日時 | 2026-05-20 16:52:39 |
| 合計ジャッジ時間 | 14,099 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 9 |
ソースコード
def aa(s):
res=0;d=1
while s:
if s&d:
res+=fen[s];s-=d
d<<=1
return res
def bb(m):
global p,n
res=0
for i in a:
l,r=(-i)%p+1,(m-i)%p+1
if l>r:
res+=n-(aa(l-1)-aa(r))
else:
res+=aa(r)-aa(l-1)
return res
n,k,p=map(int,input().split())
fen=[0]*(p+1)
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in b:
s=i+1;d=1
while s<=p:
if s&d:
fen[s]+=1
s+=d
d<<=1
q,w=-1,p-1
while w-q>1:
m=(q+w)//2
if bb(m)<k:
q=m
else:
w=m
print(w)