結果
| 問題 |
No.808 Kaiten Sushi?
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-03-22 22:22:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 206 ms / 2,000 ms |
| コード長 | 1,629 bytes |
| コンパイル時間 | 1,837 ms |
| コンパイル使用メモリ | 199,472 KB |
| 最終ジャッジ日時 | 2025-01-06 23:56:57 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
Int n,l;
cin>>n>>l;
set<Int> sx,sy;
for(Int i=0;i<n;i++){
Int x;
cin>>x;
sx.emplace(x);
}
for(Int i=0;i<n;i++){
Int y;
cin>>y;
sy.emplace(y);
}
Int time=0;
while(!sx.empty()){
{
Int t=time%l;
auto it=sx.upper_bound(t);
if(it==sx.end()){
time+=l-t;
time+=*sx.begin();
sx.erase(sx.begin());
}else{
time+=*it-t;
sx.erase(it);
}
}
if(sx.empty()){
Int t=time%l;
Int u=*sy.begin();
if(t<u){
time+=u-t;
}else{
time+=l-t;
time+=u;
}
break;
}
{
Int t=time%l;
Int u=0;
{
auto it=sy.upper_bound(t);
if(it==sy.end()) u=*sy.begin();
else u=*it;
}
{
auto it=sx.upper_bound(u);
if(it==sx.end()) u=*sx.begin();
else u=*it;
}
auto it=sy.upper_bound(u);
if(it==sy.begin()){
if(t<*sy.rbegin()){
time+=*sy.rbegin()-t;
}else{
time+=l-t;
time+=*sy.rbegin();
}
sy.erase(--sy.end());
}else{
--it;
if(t<*it){
time+=*it-t;
}else{
time+=l-t;
time+=*it;
}
sy.erase(it);
}
}
}
cout<<time<<endl;
return 0;
}
beet