結果
問題 | No.1597 Matrix Sort |
ユーザー | Ricky_pon |
提出日時 | 2021-07-10 15:51:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 183 ms / 1,500 ms |
コード長 | 2,184 bytes |
コンパイル時間 | 1,871 ms |
コンパイル使用メモリ | 197,876 KB |
実行使用メモリ | 121,616 KB |
最終ジャッジ日時 | 2023-09-14 19:34:12 |
合計ジャッジ時間 | 5,961 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 88 ms
121,492 KB |
testcase_04 | AC | 130 ms
121,576 KB |
testcase_05 | AC | 133 ms
121,356 KB |
testcase_06 | AC | 132 ms
121,616 KB |
testcase_07 | AC | 136 ms
121,508 KB |
testcase_08 | AC | 180 ms
121,372 KB |
testcase_09 | AC | 183 ms
121,324 KB |
testcase_10 | AC | 159 ms
121,372 KB |
testcase_11 | AC | 160 ms
121,444 KB |
testcase_12 | AC | 23 ms
4,508 KB |
testcase_13 | AC | 50 ms
16,608 KB |
testcase_14 | AC | 133 ms
121,484 KB |
testcase_15 | AC | 22 ms
4,380 KB |
testcase_16 | AC | 34 ms
16,520 KB |
testcase_17 | AC | 91 ms
121,512 KB |
testcase_18 | AC | 129 ms
121,436 KB |
testcase_19 | AC | 117 ms
121,356 KB |
testcase_20 | AC | 85 ms
121,444 KB |
testcase_21 | AC | 74 ms
121,372 KB |
testcase_22 | AC | 118 ms
121,452 KB |
testcase_23 | AC | 146 ms
121,452 KB |
testcase_24 | AC | 17 ms
4,376 KB |
testcase_25 | AC | 16 ms
4,380 KB |
testcase_26 | AC | 2 ms
4,380 KB |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | AC | 2 ms
4,376 KB |
testcase_29 | AC | 76 ms
120,696 KB |
ソースコード
#include <bits/stdc++.h> #define For(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rFor(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i) #define rep(i, n) For(i, 0, (n)) #define rrep(i, n) rFor(i, (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template <class T> T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template <typename T> struct coord_comp { vector<T> v; bool sorted = false; coord_comp() {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } T &operator[](int i) { return v[i]; } }; constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 200010; constexpr int MAX2 = 3 * 50 * MAX; int n, P, a[MAX], b[MAX], cnt[MAX2]; lint K; bool check(int x) { lint tmp = 0; rep(i, n) tmp += cnt[x + P - a[i] + 1] - cnt[P - a[i]]; return tmp >= K; } int main() { scanf("%d%lld%d", &n, &K, &P); rep(i, n) scanf("%d", &a[i]); rep(i, n) { scanf("%d", &b[i]); ++cnt[b[i] + 1]; ++cnt[b[i] + 1 + P]; ++cnt[b[i] + 1 + P * 2]; } partial_sum(cnt, cnt + P * 3, cnt); if (check(0)) { printf("%d\n", 0); return 0; } int low = 0, high = P - 1; while (high - low > 1) { int mid = (high + low) / 2; (check(mid) ? high : low) = mid; } printf("%d\n", high); }