結果

問題 No.1597 Matrix Sort
ユーザー nishi5451nishi5451
提出日時 2021-08-02 19:46:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 978 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 169,976 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-14 20:53:04
合計ジャッジ時間 9,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 1,439 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 421 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 440 ms
4,352 KB
testcase_25 AC 46 ms
4,352 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e+9+7;


int main(){
	int n, k;
	ll p;
	cin >> n >> k >> p;
	vector<int> a(n),b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	sort(b.begin(),b.end());
	int left = 0, right = p;
	while(right-left > 1){
		int mid = (right+left) / 2;
		ll cnt = 0;
		rep(i,n){
			int tar = p-a[i];
			int l = -1, r = n;
			while(r-l > 1){
				int m = (r+l) / 2;
				if(tar <= b[m]) r = m;
				else l = m;
			}
			int l1 = -1, r1 = l+1;
			while(r1-l1 > 1){
				int m1 = (r1+l1) / 2;
				if(mid < b[m1]+a[i]) r1 = m1;
				else l1 = m1;
			}
			cnt += r1;
			int l2 = r-1, r2 = n;
			while(r2-l2 > 1){
				int m2 = (r2+l2) / 2;
				if(mid < (b[m2]+a[i])%p) r2 = m2;
				else l2 = m2;
			}
			cnt += r2-r;
		}
		if(k <= cnt) right = mid;
		else left = mid;
	}
	cout << right << endl;
	return 0;
}
0