結果

問題 No.1597 Matrix Sort
ユーザー cai_lwcai_lw
提出日時 2021-07-09 22:05:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 1,500 ms
コード長 623 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 204,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 09:10:20
合計ジャッジ時間 5,744 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 125 ms
4,380 KB
testcase_04 AC 131 ms
4,376 KB
testcase_05 AC 132 ms
4,380 KB
testcase_06 AC 131 ms
4,380 KB
testcase_07 AC 129 ms
4,380 KB
testcase_08 AC 112 ms
4,376 KB
testcase_09 AC 115 ms
4,380 KB
testcase_10 AC 64 ms
4,376 KB
testcase_11 AC 75 ms
4,384 KB
testcase_12 AC 72 ms
4,376 KB
testcase_13 AC 108 ms
4,376 KB
testcase_14 AC 119 ms
4,376 KB
testcase_15 AC 63 ms
4,380 KB
testcase_16 AC 82 ms
4,380 KB
testcase_17 AC 92 ms
4,376 KB
testcase_18 AC 126 ms
4,380 KB
testcase_19 AC 97 ms
4,380 KB
testcase_20 AC 87 ms
4,376 KB
testcase_21 AC 84 ms
4,380 KB
testcase_22 AC 78 ms
4,376 KB
testcase_23 AC 72 ms
4,376 KB
testcase_24 AC 35 ms
4,380 KB
testcase_25 AC 32 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 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