結果
問題 |
No.808 Kaiten Sushi?
|
ユーザー |
![]() |
提出日時 | 2019-03-31 07:04:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 1,596 bytes |
コンパイル時間 | 901 ms |
コンパイル使用メモリ | 107,196 KB |
実行使用メモリ | 14,464 KB |
最終ジャッジ日時 | 2024-11-19 07:03:49 |
合計ジャッジ時間 | 7,868 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<ll, int> P; int n; ll l; ll x[100001], y[100001]; int main() { cin>>n>>l; set<ll> stx, sty; for(int i=0; i<n; i++){ cin>>x[i]; stx.insert(x[i]); } for(int i=0; i<n; i++){ cin>>y[i]; sty.insert(y[i]); } ll r=0; int ct=0; while(!stx.empty() && !sty.empty()){ auto itrx=stx.lower_bound(r); if(itrx==stx.end()){ ct++; r=*stx.begin(); }else{ r=*itrx; } stx.erase(r); if(stx.empty()){ if(r>*sty.begin()) ct++; r=*sty.begin(); sty.erase(sty.begin()); break; } ll r2; auto itry=sty.lower_bound(r); if(itry==sty.end()) r2=*sty.begin(); else r2=*itry; itrx=stx.lower_bound(r2); ll r1; if(itrx==stx.end()) r1=*stx.begin(); else r1=*itrx; itry=sty.lower_bound(r1); if(itry==sty.begin()){ itry=sty.end(); itry--; }else{ itry--; } if(*itry<r) ct++; r=*itry; sty.erase(itry); } ll ans=(ll)ct*l+r; cout<<ans<<endl; return 0; }