結果
| 問題 | No.1597 Matrix Sort | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-07-09 21:58:25 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 791 ms / 1,500 ms | 
| コード長 | 1,098 bytes | 
| コンパイル時間 | 1,619 ms | 
| コンパイル使用メモリ | 103,468 KB | 
| 最終ジャッジ日時 | 2025-01-22 21:41:19 | 
| ジャッジサーバーID (参考情報) | judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |     for (auto &&i : A) scanf("%d", &i);
      |                        ~~~~~^~~~~~~~~~
main.cpp:24:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     for (auto &&i : B) scanf("%d", &i);
      |                        ~~~~~^~~~~~~~~~
            
            ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
int main() {
    ll n, k, p;
    cin >> n >> k >> p;
    vector<int> A(n), B(n);
    for (auto &&i : A) scanf("%d", &i);
    for (auto &&i : B) scanf("%d", &i);
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int ng = -1, ok = p-1;
    auto f = [&](int x) -> ll {
        ll cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += upper_bound(B.begin(),B.end(), x-A[i])-lower_bound(B.begin(),B.end(), -A[i]);
            cnt += upper_bound(B.begin(),B.end(), x+p-A[i])-lower_bound(B.begin(),B.end(), p-A[i]);
        }
        return cnt;
    };
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        if(f(mid) >= k) ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
    return 0;
}
            
            
            
        