結果

問題 No.1597 Matrix Sort
ユーザー kenta255kenta255
提出日時 2021-07-10 02:37:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 205,332 KB
実行使用メモリ 4,768 KB
最終ジャッジ日時 2023-09-14 14:19:38
合計ジャッジ時間 9,392 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 334 ms
4,596 KB
testcase_05 AC 327 ms
4,608 KB
testcase_06 AC 328 ms
4,628 KB
testcase_07 AC 329 ms
4,532 KB
testcase_08 AC 279 ms
4,484 KB
testcase_09 AC 280 ms
4,484 KB
testcase_10 AC 200 ms
4,636 KB
testcase_11 AC 173 ms
4,576 KB
testcase_12 AC 153 ms
4,536 KB
testcase_13 AC 264 ms
4,524 KB
testcase_14 AC 305 ms
4,616 KB
testcase_15 AC 124 ms
4,540 KB
testcase_16 AC 181 ms
4,524 KB
testcase_17 AC 208 ms
4,488 KB
testcase_18 AC 313 ms
4,516 KB
testcase_19 AC 236 ms
4,524 KB
testcase_20 AC 204 ms
4,624 KB
testcase_21 AC 193 ms
4,528 KB
testcase_22 AC 182 ms
4,524 KB
testcase_23 AC 177 ms
4,524 KB
testcase_24 AC 41 ms
4,524 KB
testcase_25 AC 38 ms
4,524 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/modint>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数


int main(){

	// 値 x が何番目かを考える
	// x以下の要素をかぞえる
	// 二分探索

	ll N,K,P;
	cin >> N >> K >> P;

	vector<ll> A(N),B(N);
	FOR(i,0,N) cin >> A[i];
	FOR(i,0,N) cin >> B[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	ll ok=0; // K番目以下
	ll ng=P+1; // K番目より大きい

	while(ng - ok > 1){
		ll mid = (ok+ng) / 2;
		//mid 以下の要素数をかぞえる
		ll cnt = 0;
		FOR(i,0,N){
			cnt += num_eql(B,mid-A[i]);
			cnt += num_eql(B,mid+P-A[i]);
			cnt -= num_l(B,P-A[i]);
		}
		if(cnt < K){
			ok = mid;
		}else{
			ng = mid;
		}
	}

	cout << ng << endl;
}

0