結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-17 22:27:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 532 ms / 3,000 ms |
コード長 | 2,595 bytes |
コンパイル時間 | 2,325 ms |
コンパイル使用メモリ | 143,548 KB |
実行使用メモリ | 18,944 KB |
最終ジャッジ日時 | 2024-09-18 11:35:46 |
合計ジャッジ時間 | 12,827 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <deque>#include <queue>#include <set>#include <map>#include <limits>#include <cmath>#include <iomanip>#include <functional>#include <random>#include <set>#include <atcoder/string>#include <unordered_map>#include <climits>#include <atcoder/lazysegtree>using namespace std;using ll = long long;using namespace atcoder;ll value(vector<ll> &A,vector<ll> &B,ll maxC){ll N = A.size();ll minC = numeric_limits<ll>::max();for(int i = 0;i < N;i++){if (B[i] <= maxC){minC = min(minC,B[i]);continue;}if ( (A[i] + B[i])/2 <= maxC){minC = min(minC,(A[i] + B[i])/2);continue;}if (A[i] <= maxC){minC = min(minC,A[i]);continue;}return numeric_limits<ll>::max();}return maxC - minC;}ll three_search(vector<ll> &A,vector<ll> &B,ll l,ll r){// cout << l << "~" << r << endl;if (l + 2 >= r){vector<pair<ll, ll>> values;for (int i = l; i < r; i++){values.push_back({value(A,B, i), i});}sort(values.begin(), values.end());return values.front().second;}else{ll t1 = (2 * l + r) / 3;ll t2 = (l + 2 * r) / 3;ll t1_value = value(A,B, t1);ll t2_value = value(A,B, t2);if (t1_value <= t2_value){return three_search(A,B, l, t2);}else{return three_search(A,B, t1, r);}}}int solve(){ll N;cin >> N;vector<ll> A(N);vector<ll> B(N);set<pair<ll,pair<ll,ll>>> data;for(int i = 0;i < N;i++){cin >> A[i];}for(int i = 0;i < N;i++){cin >> B[i];if (A[i] > B[i]){swap(A[i],B[i]);}data.insert({B[i],{A[i],B[i]}});}ll ans = numeric_limits<ll>::max();while(true){ans = min(ans,data.rbegin()->first - data.begin()->first);auto p = *data.rbegin();if (p.first == p.second.first){break;}else if (p.first == (p.second.first + p.second.second)/2){data.insert({p.second.first,p.second});}else{data.insert({(p.second.first + p.second.second)/2,p.second});}data.erase(p);}cout << ans << endl;return 0;}int main(){// ll T;// cin >> T;// while (T--)// {solve();// }// cout << flush;return 0;}