結果
| 問題 |
No.808 Kaiten Sushi?
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2019-03-23 00:46:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,580 bytes |
| コンパイル時間 | 929 ms |
| コンパイル使用メモリ | 107,864 KB |
| 実行使用メモリ | 14,464 KB |
| 最終ジャッジ日時 | 2024-09-19 07:32:50 |
| 合計ジャッジ時間 | 7,982 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 WA * 27 |
ソースコード
#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;
r=0; ct=0;
for(int i=0; i<n; i++){
swap(x[i], y[i]);
stx.insert(x[i]); sty.insert(y[i]);
}
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);
}
ans=min(ans, (ll)ct*l+r);
cout<<ans<<endl;
return 0;
}
chocorusk