結果
問題 | No.2248 max(C)-min(C) |
ユーザー | milanis48663220 |
提出日時 | 2023-03-17 21:56:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 463 ms / 3,000 ms |
コード長 | 2,863 bytes |
コンパイル時間 | 1,547 ms |
コンパイル使用メモリ | 134,180 KB |
実行使用メモリ | 77,652 KB |
最終ジャッジ日時 | 2023-10-18 14:33:04 |
合計ジャッジ時間 | 15,665 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 3 ms
4,348 KB |
testcase_04 | AC | 3 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 4 ms
4,348 KB |
testcase_07 | AC | 4 ms
4,348 KB |
testcase_08 | AC | 5 ms
4,348 KB |
testcase_09 | AC | 5 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 5 ms
4,348 KB |
testcase_12 | AC | 3 ms
4,348 KB |
testcase_13 | AC | 3 ms
4,348 KB |
testcase_14 | AC | 4 ms
4,348 KB |
testcase_15 | AC | 5 ms
4,348 KB |
testcase_16 | AC | 3 ms
4,348 KB |
testcase_17 | AC | 4 ms
4,348 KB |
testcase_18 | AC | 396 ms
67,300 KB |
testcase_19 | AC | 42 ms
11,488 KB |
testcase_20 | AC | 457 ms
77,652 KB |
testcase_21 | AC | 435 ms
73,904 KB |
testcase_22 | AC | 290 ms
51,788 KB |
testcase_23 | AC | 173 ms
34,324 KB |
testcase_24 | AC | 62 ms
15,528 KB |
testcase_25 | AC | 412 ms
70,856 KB |
testcase_26 | AC | 358 ms
62,212 KB |
testcase_27 | AC | 412 ms
70,404 KB |
testcase_28 | AC | 31 ms
9,648 KB |
testcase_29 | AC | 379 ms
64,312 KB |
testcase_30 | AC | 134 ms
28,032 KB |
testcase_31 | AC | 455 ms
77,652 KB |
testcase_32 | AC | 73 ms
17,372 KB |
testcase_33 | AC | 124 ms
25,996 KB |
testcase_34 | AC | 463 ms
77,640 KB |
testcase_35 | AC | 462 ms
77,652 KB |
testcase_36 | AC | 461 ms
77,652 KB |
testcase_37 | AC | 220 ms
41,392 KB |
testcase_38 | AC | 438 ms
70,104 KB |
testcase_39 | AC | 427 ms
70,068 KB |
testcase_40 | AC | 428 ms
70,056 KB |
testcase_41 | AC | 361 ms
60,148 KB |
testcase_42 | AC | 425 ms
70,080 KB |
testcase_43 | AC | 376 ms
63,248 KB |
testcase_44 | AC | 429 ms
70,068 KB |
testcase_45 | AC | 327 ms
55,524 KB |
testcase_46 | AC | 159 ms
31,888 KB |
testcase_47 | AC | 434 ms
70,068 KB |
testcase_48 | AC | 130 ms
38,300 KB |
testcase_49 | AC | 445 ms
77,628 KB |
testcase_50 | AC | 443 ms
77,628 KB |
testcase_51 | AC | 452 ms
77,628 KB |
testcase_52 | AC | 448 ms
77,628 KB |
testcase_53 | AC | 58 ms
15,432 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template<typename T> class Compress{ public: vector<T> data; int offset; Compress(vector<T> data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; const ll inf = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<ll> a(n), b(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; vector<ll> v; for(int i = 0; i < n; i++){ if(a[i] > b[i]) swap(a[i], b[i]); v.push_back(a[i]); v.push_back(b[i]); v.push_back((a[i]+b[i])/2); } auto cp = Compress<ll>(v); int m = cp.size(); auto indices = vec2d(3, m, vector<int>()); for(int i = 0; i < n; i++){ indices[0][cp[a[i]]].push_back(i); indices[1][cp[(a[i]+b[i])/2]].push_back(i); indices[2][cp[b[i]]].push_back(i); } ll ans = inf; ll mx = *max_element(a.begin(), a.end()); for(int i = 0; i < m; i++){ int x = cp.data[i]; chmin(ans, mx-x); for(int idx: indices[0][i]){ chmax(mx, (a[idx]+b[idx])/2); } for(int idx: indices[1][i]){ chmax(mx, b[idx]); } for(int idx: indices[2][i]){ chmax(mx, inf); } } cout << ans << endl; }