結果

問題 No.1597 Matrix Sort
ユーザー cureskolcureskol
提出日時 2021-07-09 21:50:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 4,104 ms
コンパイル使用メモリ 169,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 08:31:36
合計ジャッジ時間 13,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 364 ms
4,376 KB
testcase_05 AC 418 ms
4,376 KB
testcase_06 AC 424 ms
4,376 KB
testcase_07 AC 447 ms
4,376 KB
testcase_08 AC 337 ms
4,380 KB
testcase_09 AC 433 ms
4,384 KB
testcase_10 AC 384 ms
4,380 KB
testcase_11 AC 318 ms
4,380 KB
testcase_12 AC 209 ms
4,380 KB
testcase_13 AC 320 ms
4,380 KB
testcase_14 AC 391 ms
4,380 KB
testcase_15 AC 210 ms
4,380 KB
testcase_16 AC 317 ms
4,376 KB
testcase_17 AC 365 ms
4,376 KB
testcase_18 AC 369 ms
4,380 KB
testcase_19 AC 354 ms
4,376 KB
testcase_20 AC 369 ms
4,380 KB
testcase_21 AC 386 ms
4,380 KB
testcase_22 AC 361 ms
4,380 KB
testcase_23 AC 382 ms
4,380 KB
testcase_24 AC 47 ms
4,380 KB
testcase_25 AC 45 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;
int S(vector<int> &b,int a){//a以上の個数
  int L=-1,R=b.size();//Lはa未満
  while(R-L>1){
    int m=(L+R)>>1;
    (b[m]<a?L:R)=m;
  }
  return b.size()-1-L;
}

int main(){
  ll n,k,p;cin>>n>>k>>p;
  vector<int> a(n),b(n);
  REP(i,n)cin>>a[i];
  REP(i,n)cin>>b[i];
  sort(ALL(a));
  sort(ALL(b));
  int l=0,r=p;//lはk子未満,rはより少ない
  while(r-l>1){
    int m=(l+r)>>1;
    ll cnt=0;//m以下の個数を数える
    REP(i,n){
      if(a[i]<=m){//0<=x<=m-a[i]の個数
        int A=S(b,0);
        int B=S(b,m-a[i]+1);
        cnt+=A-B;
        cnt+=S(b,p-a[i]);
      }
      else{//p-a[i]<=x<=p+m-a[i]の個数
        int A=S(b,p-a[i]);
        int B=S(b,p+m-a[i]+1);
        cnt+=A-B;
      }
    }
    //cout<<m<<" "<<cnt<<endl;
    (cnt<k?l:r)=m;
  }
  cout<<r<<endl;
}
0