結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 338 ms
4,504 KB
testcase_05 AC 331 ms
4,556 KB
testcase_06 AC 330 ms
4,616 KB
testcase_07 AC 339 ms
4,528 KB
testcase_08 AC 278 ms
4,552 KB
testcase_09 AC 272 ms
4,500 KB
testcase_10 AC 203 ms
4,656 KB
testcase_11 AC 165 ms
4,556 KB
testcase_12 AC 144 ms
4,528 KB
testcase_13 AC 266 ms
4,492 KB
testcase_14 AC 307 ms
4,548 KB
testcase_15 AC 129 ms
4,612 KB
testcase_16 AC 183 ms
4,792 KB
testcase_17 AC 209 ms
4,476 KB
testcase_18 AC 334 ms
4,468 KB
testcase_19 AC 248 ms
4,656 KB
testcase_20 AC 202 ms
4,532 KB
testcase_21 AC 197 ms
4,552 KB
testcase_22 AC 191 ms
4,520 KB
testcase_23 AC 180 ms
4,468 KB
testcase_24 AC 53 ms
4,612 KB
testcase_25 AC 53 ms
4,536 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 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以下の要素をかぞえる
	// 初めてK個以上になる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 ng=0; // K個より少ない
	ll ok=P+8; // K個以上

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

	cout << ok << endl;
}

0