結果

問題 No.1597 Matrix Sort
ユーザー cai_lwcai_lw
提出日時 2021-07-09 22:05:41
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 130 ms / 1,500 ms
コード長 623 bytes
コンパイル時間 1,966 ms
使用メモリ 3,964 KB
最終ジャッジ日時 2023-02-01 23:37:21
合計ジャッジ時間 5,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,388 KB
testcase_01 AC 1 ms
3,484 KB
testcase_02 AC 2 ms
3,440 KB
testcase_03 AC 122 ms
3,844 KB
testcase_04 AC 127 ms
3,912 KB
testcase_05 AC 130 ms
3,888 KB
testcase_06 AC 127 ms
3,880 KB
testcase_07 AC 125 ms
3,888 KB
testcase_08 AC 109 ms
3,860 KB
testcase_09 AC 111 ms
3,948 KB
testcase_10 AC 62 ms
3,860 KB
testcase_11 AC 71 ms
3,924 KB
testcase_12 AC 69 ms
3,808 KB
testcase_13 AC 106 ms
3,864 KB
testcase_14 AC 115 ms
3,856 KB
testcase_15 AC 59 ms
3,868 KB
testcase_16 AC 80 ms
3,928 KB
testcase_17 AC 90 ms
3,808 KB
testcase_18 AC 124 ms
3,840 KB
testcase_19 AC 94 ms
3,864 KB
testcase_20 AC 84 ms
3,904 KB
testcase_21 AC 81 ms
3,964 KB
testcase_22 AC 76 ms
3,932 KB
testcase_23 AC 70 ms
3,840 KB
testcase_24 AC 34 ms
3,884 KB
testcase_25 AC 31 ms
3,808 KB
testcase_26 AC 1 ms
3,464 KB
testcase_27 AC 1 ms
3,408 KB
testcase_28 AC 1 ms
3,376 KB
testcase_29 AC 1 ms
3,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  int n,p;
  ll k;
  cin>>n>>k>>p;
  vector<int> a(n),b(n);
  for(int &x:a){
    cin>>x;
    x%=p;
  }
  for(int &x:b){
    cin>>x;
    x%=p;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int lo=0,hi=p;
  while(hi-lo>1){
    int mid=(lo+hi)/2;
    ll cnt=0;
    int j1=n-1,j2=n-1,j3=n-1;
    for(int i=0;i<n;i++){
      while(j1>=0&&a[i]+b[j1]>=mid)j1--;
      while(j2>=0&&a[i]+b[j2]>=p)j2--;
      while(j3>=0&&a[i]+b[j3]>=p+mid)j3--;
      cnt+=j1+1+j3-j2;
    }
    if(cnt>=k)hi=mid;
    else lo=mid;
  }
  cout<<lo<<endl;
}
0