結果
問題 | No.2248 max(C)-min(C) |
ユーザー | 👑 AngrySadEight |
提出日時 | 2023-03-11 00:56:16 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 346 ms / 3,000 ms |
コード長 | 3,919 bytes |
コンパイル時間 | 6,718 ms |
コンパイル使用メモリ | 314,540 KB |
実行使用メモリ | 28,500 KB |
最終ジャッジ日時 | 2024-09-18 05:53:42 |
合計ジャッジ時間 | 16,235 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 3 ms
6,812 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 5 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,944 KB |
testcase_06 | AC | 5 ms
6,940 KB |
testcase_07 | AC | 5 ms
6,944 KB |
testcase_08 | AC | 6 ms
6,944 KB |
testcase_09 | AC | 5 ms
6,940 KB |
testcase_10 | AC | 3 ms
6,940 KB |
testcase_11 | AC | 6 ms
6,940 KB |
testcase_12 | AC | 4 ms
6,940 KB |
testcase_13 | AC | 5 ms
6,944 KB |
testcase_14 | AC | 6 ms
6,940 KB |
testcase_15 | AC | 5 ms
6,944 KB |
testcase_16 | AC | 5 ms
6,944 KB |
testcase_17 | AC | 5 ms
6,944 KB |
testcase_18 | AC | 268 ms
25,336 KB |
testcase_19 | AC | 25 ms
6,940 KB |
testcase_20 | AC | 205 ms
27,004 KB |
testcase_21 | AC | 193 ms
26,136 KB |
testcase_22 | AC | 138 ms
21,832 KB |
testcase_23 | AC | 91 ms
15,192 KB |
testcase_24 | AC | 37 ms
7,960 KB |
testcase_25 | AC | 189 ms
26,580 KB |
testcase_26 | AC | 165 ms
23,644 KB |
testcase_27 | AC | 203 ms
25,636 KB |
testcase_28 | AC | 21 ms
6,944 KB |
testcase_29 | AC | 174 ms
24,648 KB |
testcase_30 | AC | 74 ms
12,308 KB |
testcase_31 | AC | 209 ms
28,364 KB |
testcase_32 | AC | 42 ms
8,372 KB |
testcase_33 | AC | 68 ms
10,288 KB |
testcase_34 | AC | 213 ms
27,384 KB |
testcase_35 | AC | 206 ms
27,256 KB |
testcase_36 | AC | 203 ms
28,056 KB |
testcase_37 | AC | 110 ms
15,556 KB |
testcase_38 | AC | 268 ms
27,936 KB |
testcase_39 | AC | 264 ms
27,648 KB |
testcase_40 | AC | 264 ms
28,288 KB |
testcase_41 | AC | 225 ms
24,500 KB |
testcase_42 | AC | 270 ms
27,004 KB |
testcase_43 | AC | 236 ms
25,268 KB |
testcase_44 | AC | 266 ms
28,500 KB |
testcase_45 | AC | 204 ms
24,312 KB |
testcase_46 | AC | 103 ms
13,516 KB |
testcase_47 | AC | 265 ms
28,344 KB |
testcase_48 | AC | 205 ms
27,388 KB |
testcase_49 | AC | 345 ms
27,132 KB |
testcase_50 | AC | 344 ms
27,392 KB |
testcase_51 | AC | 345 ms
28,444 KB |
testcase_52 | AC | 346 ms
27,388 KB |
testcase_53 | AC | 47 ms
7,928 KB |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define repk(i, k, n) for (int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 #define mod3 100000007 #define vi vector<int> #define vs vector<string> #define vc vector<char> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vector<int>> #define vvc vector<vector<char>> #define vvl vector<vector<ll>> #define vvb vector<vector<bool>> #define vvvi vector<vector<vector<int>>> #define vvvl vector<vector<vector<ll>>> #define pii pair<int,int> #define pil pair<int,ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define vvpii vector<vector<pair<int,int>>> #define vvpll vector<vector<pair<ll,ll>>> template<typename T> void debug(T e){ cerr << e << endl; } template<typename T> void debug(vector<T> &v){ rep(i, v.size()){ cerr << v[i] << " "; } cerr << endl; } template<typename T> void debug(vector<vector<T>> &v){ rep(i, v.size()){ rep(j, v[i].size()){ cerr << v[i][j] << " "; } cerr << endl; } } template<typename T> void debug(vector<pair<T, T>> &v){ rep(i,v.size()){ cerr << v[i].first << " " << v[i].second << endl; } } template<typename T> void debug(set<T> &st){ for (auto itr = st.begin(); itr != st.end(); itr++){ cerr << *itr << " "; } cerr << endl; } template<typename T> void debug(multiset<T> &ms){ for (auto itr = ms.begin(); itr != ms.end(); itr++){ cerr << *itr << " "; } cerr << endl; } template<typename T> void debug(map<T, T> &mp){ for (auto itr = mp.begin(); itr != mp.end(); itr++){ cerr << itr->first << " " << itr->second << endl; } } void debug_out(){ cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T){ cerr << H << " "; debug_out(T...); } int main(){ ll N; cin >> N; vl A(N); vl B(N); rep(i,N) cin >> A[i]; rep(i,N) cin >> B[i]; assert(1 <= N && N <= 200000); for (ll i = 0; i < N; i++){ assert(0 <= A[i] && A[i] <= 1000000000); assert(0 <= B[i] && B[i] <= 1000000000); assert(A[i] % 2 == 0); assert(B[i] % 2 == 0); } /*vvpll C(N, vpll(0)); for (ll i = 0; i < N; i++){ C.push_back(pll(A[i], i)); C.push_back(pll(B[i], i)); C.push_back(pll((A[i] + B[i]) / 2, i)); } sort(all(C));*/ vvl vec(N, vl(0)); for (ll i = 0; i < N; i++){ vec[i].push_back(A[i]); vec[i].push_back(B[i]); vec[i].push_back((A[i] + B[i]) / 2); } for (ll i = 0; i < N; i++){ sort(all(vec[i])); } priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> pque; ll max_val = 0; ll min_val = 1000000001; for (ll i = 0; i < N; i++){ pque.push(tuple<ll, ll, ll>(vec[i][0], i, 0)); max_val = max(max_val, vec[i][0]); min_val = min(min_val, vec[i][0]); } ll ans = max_val - min_val; while(true){ tuple<ll, ll, ll> t = pque.top(); pque.pop(); ll val = get<0>(t); ll idx = get<1>(t); ll order = get<2>(t); if (order == 2){ break; } pque.push(tuple<ll, ll, ll>(vec[idx][order + 1], idx, order + 1)); max_val = max(max_val, vec[idx][order + 1]); tuple<ll, ll, ll> t2 = pque.top(); min_val = get<0>(t2); ans = min(ans, max_val - min_val); //debug_out(max_val, min_val); } cout << ans << endl; }