結果

問題 No.1597 Matrix Sort
ユーザー nishi5451nishi5451
提出日時 2021-08-02 19:47:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,225 ms / 1,500 ms
コード長 979 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 170,068 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-14 20:53:41
合計ジャッジ時間 24,188 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1,127 ms
4,376 KB
testcase_04 AC 1,201 ms
4,368 KB
testcase_05 AC 1,225 ms
4,372 KB
testcase_06 AC 1,173 ms
4,372 KB
testcase_07 AC 1,201 ms
4,372 KB
testcase_08 AC 1,098 ms
4,368 KB
testcase_09 AC 1,145 ms
4,372 KB
testcase_10 AC 406 ms
4,372 KB
testcase_11 AC 755 ms
4,368 KB
testcase_12 AC 698 ms
4,372 KB
testcase_13 AC 994 ms
4,372 KB
testcase_14 AC 1,133 ms
4,372 KB
testcase_15 AC 478 ms
4,372 KB
testcase_16 AC 803 ms
4,372 KB
testcase_17 AC 971 ms
4,372 KB
testcase_18 AC 1,167 ms
4,372 KB
testcase_19 AC 1,173 ms
4,368 KB
testcase_20 AC 1,165 ms
4,372 KB
testcase_21 AC 1,114 ms
4,372 KB
testcase_22 AC 940 ms
4,372 KB
testcase_23 AC 810 ms
4,368 KB
testcase_24 AC 86 ms
4,368 KB
testcase_25 AC 60 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,368 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, p;
	ll k;
	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 = -1, 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