結果
問題 | No.1597 Matrix Sort |
ユーザー |
![]() |
提出日時 | 2021-07-10 15:51:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 237 ms / 1,500 ms |
コード長 | 2,184 bytes |
コンパイル時間 | 2,261 ms |
コンパイル使用メモリ | 191,932 KB |
最終ジャッジ日時 | 2025-01-23 00:19:10 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:86:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 86 | scanf("%d%lld%d", &n, &K, &P); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:87:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 87 | rep(i, n) scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:89:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 89 | scanf("%d", &b[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#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); }