結果
問題 | No.2248 max(C)-min(C) |
ユーザー | nagisa5101 |
提出日時 | 2023-03-25 05:07:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,865 ms / 3,000 ms |
コード長 | 2,602 bytes |
コンパイル時間 | 5,283 ms |
コンパイル使用メモリ | 277,532 KB |
実行使用メモリ | 110,256 KB |
最終ジャッジ日時 | 2023-10-18 21:57:01 |
合計ジャッジ時間 | 52,960 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 4 ms
4,348 KB |
testcase_04 | AC | 3 ms
4,348 KB |
testcase_05 | AC | 3 ms
4,348 KB |
testcase_06 | AC | 6 ms
4,620 KB |
testcase_07 | AC | 7 ms
4,644 KB |
testcase_08 | AC | 7 ms
4,644 KB |
testcase_09 | AC | 6 ms
4,644 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 7 ms
4,644 KB |
testcase_12 | AC | 4 ms
4,348 KB |
testcase_13 | AC | 5 ms
4,460 KB |
testcase_14 | AC | 6 ms
4,644 KB |
testcase_15 | AC | 7 ms
4,644 KB |
testcase_16 | AC | 4 ms
4,348 KB |
testcase_17 | AC | 6 ms
4,576 KB |
testcase_18 | AC | 1,527 ms
96,860 KB |
testcase_19 | AC | 101 ms
15,604 KB |
testcase_20 | AC | 1,786 ms
110,188 KB |
testcase_21 | AC | 1,722 ms
104,976 KB |
testcase_22 | AC | 1,094 ms
74,028 KB |
testcase_23 | AC | 590 ms
48,820 KB |
testcase_24 | AC | 175 ms
21,316 KB |
testcase_25 | AC | 1,660 ms
100,224 KB |
testcase_26 | AC | 1,401 ms
89,272 KB |
testcase_27 | AC | 1,616 ms
99,500 KB |
testcase_28 | AC | 79 ms
12,788 KB |
testcase_29 | AC | 1,428 ms
92,372 KB |
testcase_30 | AC | 426 ms
39,648 KB |
testcase_31 | AC | 1,865 ms
110,188 KB |
testcase_32 | AC | 209 ms
23,884 KB |
testcase_33 | AC | 396 ms
36,528 KB |
testcase_34 | AC | 1,862 ms
110,188 KB |
testcase_35 | AC | 1,833 ms
110,188 KB |
testcase_36 | AC | 1,830 ms
110,188 KB |
testcase_37 | AC | 781 ms
58,852 KB |
testcase_38 | AC | 1,720 ms
96,332 KB |
testcase_39 | AC | 1,658 ms
96,332 KB |
testcase_40 | AC | 1,649 ms
96,332 KB |
testcase_41 | AC | 1,368 ms
84,256 KB |
testcase_42 | AC | 1,630 ms
96,332 KB |
testcase_43 | AC | 1,424 ms
86,896 KB |
testcase_44 | AC | 1,650 ms
96,332 KB |
testcase_45 | AC | 1,210 ms
77,724 KB |
testcase_46 | AC | 529 ms
44,596 KB |
testcase_47 | AC | 1,628 ms
96,332 KB |
testcase_48 | AC | 311 ms
42,512 KB |
testcase_49 | AC | 1,670 ms
110,256 KB |
testcase_50 | AC | 1,664 ms
110,256 KB |
testcase_51 | AC | 1,679 ms
110,256 KB |
testcase_52 | AC | 1,652 ms
110,256 KB |
testcase_53 | AC | 159 ms
21,168 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repll(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, n, m) for (int i = n; i < (int)(m); i++) #define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++) #define all(v) v.begin(),v.end() using ll=long long; using ld=long double; using vi=vector<int>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vl=vector<ll>; using vvl=vector<vl>; using vvvl=vector<vvl>; using vld=vector<ld>; using vvld=vector<vld>; int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,1,0,-1,1,-1,1,-1}; const double PI = acos(-1); //const ll MOD=1e9+7; //const ll MOD=998244353; const ll INF=(1LL<<60); const int INF2=(1<<30); //using mint=modint1000000007; //using mint=modint998244353; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n;cin>>n; set<ll> val; vl a(n,0),b(n,0); rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; rep(i,n)val.insert(a[i]); rep(i,n)val.insert(b[i]); rep(i,n)val.insert((a[i]+b[i])/2); ll sz=val.size(); map<ll,ll> val_to_index; vl index_to_val(sz,0); int now=0; for(auto ite=val.begin();ite!=val.end();ite++){ val_to_index[*ite]=now; index_to_val[now]=*ite; now++; } vvi index_to_index(sz); //index_to_val[i]にあたる値を持っている添字 rep(i,n){ int index=val_to_index[a[i]]; index_to_index[index].push_back(i); index=val_to_index[b[i]]; index_to_index[index].push_back(i); index=val_to_index[(a[i]+b[i])/2]; index_to_index[index].push_back(i); } ll ans=INF; int left=0,right=-1; int f=0; vi cnt(n,0); int c=0; while(1){ if(f==0){ right++; if(right==sz)break; int v=index_to_val[right]; for(auto i:index_to_index[right]){ cnt[i]++; if(cnt[i]==1){ c++; if(c==n)f=1; } } } else{ for(auto i:index_to_index[left]){ cnt[i]--; if(cnt[i]==0){ c--; f=0; } } left++; } if(f){ ll u=index_to_val[left],v=index_to_val[right]; ans=min(ans,v-u); } } cout<<ans<<endl; return 0; }