結果
問題 | No.1597 Matrix Sort |
ユーザー |
![]() |
提出日時 | 2021-07-09 22:11:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 735 ms / 1,500 ms |
コード長 | 1,854 bytes |
コンパイル時間 | 1,852 ms |
コンパイル使用メモリ | 173,700 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 16:40:42 |
合計ジャッジ時間 | 13,677 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define ll long long#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)#define Pr pair<ll,ll>#define Tp tuple<ll,ll,ll>using Graph = vector<vector<int>>;ll mod = 1000000007;//mod逆元long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}//Combination2//10^6くらいまで//modはグローバルに定義しておくvector<ll> fact;vector<ll> invf;ll comb(ll n,ll k){if(n<0||k<0||k>n) return 0LL;else{ll a = fact[n]*invf[k]%mod;a = a*invf[n-k]%mod;return a;}}/*//main関数内に以下ペースト//N:maxfact.assign(2*N+1,1LL);invf.assign(2*N+1,1LL);rep(i,2*N) fact[i+1] = fact[i]*(i+1)%mod;rep(i,2*N+1) invf[i] = modinv(fact[i],mod);*/int main() {ll N,K,P; cin >> N >> K >> P;ll a[N]; vector<ll> b;rep(i,N) cin >> a[i];rep(i,N){ll d; cin >> d;b.push_back(d);}sort(b.begin(),b.end());//解から二分探索 binary search//分かれ目の"r"側の値を求めるll l,r,ans;l = 0; r = P; //初期値の代入while(l<r){ll c = (l+r)/2;//cの場合に検証ll cnt = 0;rep(i,N){cnt -= lower_bound(b.begin(),b.end(),0LL)-b.begin();cnt += lower_bound(b.begin(),b.end(),c-a[i]+1)-b.begin();cnt -= lower_bound(b.begin(),b.end(),P-a[i])-b.begin();cnt += lower_bound(b.begin(),b.end(),P+c-a[i]+1)-b.begin();}if(cnt<K){//cが"l側"になる条件判定l = c+1;}else r = c;}ans = l;cout << ans << endl;}