結果

問題 No.1597 Matrix Sort
ユーザー kenta255kenta255
提出日時 2021-07-10 02:38:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 1,500 ms
コード長 1,244 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 205,476 KB
実行使用メモリ 4,784 KB
最終ジャッジ日時 2023-09-14 14:20:43
合計ジャッジ時間 9,078 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 326 ms
4,512 KB
testcase_04 AC 341 ms
4,576 KB
testcase_05 AC 338 ms
4,784 KB
testcase_06 AC 338 ms
4,624 KB
testcase_07 AC 338 ms
4,560 KB
testcase_08 AC 277 ms
4,604 KB
testcase_09 AC 285 ms
4,556 KB
testcase_10 AC 201 ms
4,632 KB
testcase_11 AC 175 ms
4,564 KB
testcase_12 AC 156 ms
4,620 KB
testcase_13 AC 269 ms
4,572 KB
testcase_14 AC 313 ms
4,604 KB
testcase_15 AC 126 ms
4,600 KB
testcase_16 AC 184 ms
4,520 KB
testcase_17 AC 211 ms
4,564 KB
testcase_18 AC 327 ms
4,520 KB
testcase_19 AC 244 ms
4,616 KB
testcase_20 AC 208 ms
4,560 KB
testcase_21 AC 202 ms
4,560 KB
testcase_22 AC 193 ms
4,572 KB
testcase_23 AC 186 ms
4,676 KB
testcase_24 AC 47 ms
4,560 KB
testcase_25 AC 45 ms
4,572 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 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=-1; // 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