結果

問題 No.1597 Matrix Sort
ユーザー Mr.SpockMr.Spock
提出日時 2021-07-18 15:32:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 1,500 ms
コード長 1,106 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 168,820 KB
実行使用メモリ 160,992 KB
最終ジャッジ日時 2023-09-22 17:54:48
合計ジャッジ時間 5,973 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 155 ms
160,696 KB
testcase_04 AC 164 ms
160,700 KB
testcase_05 AC 180 ms
160,816 KB
testcase_06 AC 182 ms
160,836 KB
testcase_07 AC 178 ms
160,836 KB
testcase_08 AC 148 ms
160,992 KB
testcase_09 AC 173 ms
160,968 KB
testcase_10 AC 107 ms
160,808 KB
testcase_11 AC 110 ms
160,832 KB
testcase_12 AC 23 ms
4,944 KB
testcase_13 AC 51 ms
20,388 KB
testcase_14 AC 172 ms
160,860 KB
testcase_15 AC 26 ms
4,948 KB
testcase_16 AC 42 ms
20,420 KB
testcase_17 AC 127 ms
160,820 KB
testcase_18 AC 163 ms
160,900 KB
testcase_19 AC 161 ms
160,884 KB
testcase_20 AC 125 ms
160,860 KB
testcase_21 AC 120 ms
160,812 KB
testcase_22 AC 117 ms
160,900 KB
testcase_23 AC 113 ms
160,836 KB
testcase_24 AC 15 ms
4,752 KB
testcase_25 AC 14 ms
4,616 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 87 ms
159,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void logger(std::string, Args&& ...)’ 内:
main.cpp:9:53: 警告: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
    9 |         (..., (cout << delim << values, delim = ", "));
      |                                                     ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
	cout << vars << " = [";
	string delim = "";
	(..., (cout << delim << values, delim = ", "));
	cout << "]" << " ";
}
ll n, k, p;
vector<ll>x, y, dp;
bool solve(ll mid) {
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ans += dp[p + mid - x[i]] - dp[p - x[i] - 1];
		if (mid - x[i] >= 0) {
			ans += dp[mid - x[i]];
		}
	}
	return (ans >= k);
}
void solve() {
	cin >> n >> k >> p;
	x.resize(n);
	y.resize(n);
	dp.resize(2 * p + 1);
	dp.assign(2 * p + 1, 0);
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i < n; i++) {
		dp[y[i]]++;
	}
	for (ll i = 1; i <= 2 * p; i++) {
		dp[i] += dp[i - 1];
	}
	ll L = -1, R = p + 1;
	while (R - L > 1) {
		ll mid = (L + R) / 2;
		if (solve(mid))R = mid;
		else L = mid;
	}
	cout << R << endl;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T;
	T = 1;
	//cin >> T;
	while (T--) {
		solve();
	}
}
0