結果
問題 | No.1597 Matrix Sort |
ユーザー | tomo0608 |
提出日時 | 2021-07-09 22:16:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 149 ms / 1,500 ms |
コード長 | 4,646 bytes |
コンパイル時間 | 5,021 ms |
コンパイル使用メモリ | 279,692 KB |
実行使用メモリ | 160,952 KB |
最終ジャッジ日時 | 2023-09-14 09:30:33 |
合計ジャッジ時間 | 8,776 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 133 ms
160,948 KB |
testcase_04 | AC | 131 ms
160,880 KB |
testcase_05 | AC | 143 ms
160,860 KB |
testcase_06 | AC | 149 ms
160,832 KB |
testcase_07 | AC | 149 ms
160,932 KB |
testcase_08 | AC | 117 ms
160,940 KB |
testcase_09 | AC | 141 ms
160,816 KB |
testcase_10 | AC | 87 ms
160,952 KB |
testcase_11 | AC | 90 ms
160,752 KB |
testcase_12 | AC | 34 ms
4,896 KB |
testcase_13 | AC | 54 ms
20,244 KB |
testcase_14 | AC | 139 ms
160,932 KB |
testcase_15 | AC | 29 ms
5,000 KB |
testcase_16 | AC | 45 ms
20,316 KB |
testcase_17 | AC | 106 ms
160,820 KB |
testcase_18 | AC | 124 ms
160,940 KB |
testcase_19 | AC | 111 ms
160,876 KB |
testcase_20 | AC | 99 ms
160,812 KB |
testcase_21 | AC | 94 ms
160,756 KB |
testcase_22 | AC | 91 ms
160,828 KB |
testcase_23 | AC | 89 ms
160,824 KB |
testcase_24 | AC | 19 ms
4,620 KB |
testcase_25 | AC | 17 ms
4,628 KB |
testcase_26 | AC | 1 ms
4,376 KB |
testcase_27 | AC | 1 ms
4,376 KB |
testcase_28 | AC | 2 ms
4,376 KB |
testcase_29 | AC | 62 ms
159,240 KB |
ソースコード
/** * author: tomo0608 * created: 09.07.2021 21:52:08 **/ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include<atcoder/all> using namespace atcoder; #endif typedef long long ll; typedef long double ld; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; typedef pair<int,int> pii; typedef pair<long long, long long> pll; #define all(x) x.begin(),x.end() #define rep1(a) for(long long i = 0; i < a; i++) #define rep2(i, a) for(long long i = 0; i < a; i++) #define rep3(i, a, b) for(long long i = a; i < b; i++) #define rep4(i, a, b, c) for(long long i = a; i < b; i += c) #define drep1(a) for(long long i = a-1; i >= 0; i--) #define drep2(i, a) for(long long i = a-1; i >= 0; i--) #define drep3(i, a, b) for(long long i = a-1; i >= b; i--) #define drep4(i, a, b, c) for(long long i = a-1; i >= b; i -= c) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define drep(...) overload4(__VA_ARGS__, drep4, drep3, drep2, drep1)(__VA_ARGS__) #define unique(a) a.erase(unique(a.begin(),a.end()),a.end()) template<class... T>void input(T&... a){(cin >> ... >> a);}; #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) #define STRING(...) string __VA_ARGS__; input(__VA_ARGS__) void print(){cout << '\n';} template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';} template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; } template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;} #ifdef __LOCAL void debug_out(){ cerr << endl;} template < class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...);} #define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) #define mp make_pair #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;} #define endl '\n' int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; void solve(){ LL(n,k,p); V<ll> a(n),b(n);cin >> a >> b; sort(all(a)), sort(all(b)); V<ll> sum_b(2*p,0); rep(i,n)sum_b[b[i]]++; rep(i,2*p-1)sum_b[i+1] += sum_b[i]; ll ok = p-1, ng = -1; auto check = [&](ll x)->bool{ // a[i] + b[j] <= x or p <= a[i] + b[j] <= p + x となるものがk個以上あるか ll s = 0; rep(i,n){ // b[j] <= x - a[i] or p - a[i]-1 < b[j] <= p + x - a[i] s += sum_b[p+x-a[i]] - sum_b[p-a[i]-1]; if(x-a[i] >= 0)s += sum_b[x-a[i]]; } return s >= k; }; while(ok - ng > 1){ ll mid = (ok + ng)/2; if(check(mid))ok = mid; else ng = mid; } print(ok); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << setprecision(20); int codeforces = 1; //cin >> codeforces; while(codeforces--){ solve(); } return 0; }