結果
| 問題 |
No.808 Kaiten Sushi?
|
| コンテスト | |
| ユーザー |
sinsincoscos
|
| 提出日時 | 2019-03-01 22:47:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,453 bytes |
| コンパイル時間 | 858 ms |
| コンパイル使用メモリ | 67,816 KB |
| 実行使用メモリ | 16,336 KB |
| 最終ジャッジ日時 | 2024-09-14 01:16:34 |
| 合計ジャッジ時間 | 33,505 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 48 TLE * 5 -- * 3 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
ll N,L,X[100010],Y[100010];
int use[100010] = {};
vector<P> v;
ll del(ll x,ll y){
if(x<y) return y-x;
else return L-x+y;
}
int main(){
cin >> N >> L;
for(int i=1;i<=N;i++){
cin >> X[i];
}
for(int i=1;i<=N;i++){
cin >> Y[i];
}
for(int i=1;i<=N;i++){
v.push_back(P(X[i],1));
v.push_back(P(Y[i],-1));
}
sort(v.begin(),v.end());
ll ans = 0,now_d = 0;
int cnt = 0,now = 0;
bool sushi = false;
while(cnt<2*N){
if(!sushi){
for(int j=0;j<=4*N;j++){
if(use[(now+j)%(2*N)]==1) continue;
if(v[(now+j)%(2*N)].second==1){
sushi = true;
ans += del(now_d,v[(now+j)%(2*N)].first);
now_d = v[(now+j)%(2*N)].first;
use[(now+j)%(2*N)] = 1;
now = (now+j)%(2*N);
break;
}
}
}else{
int ocha_id = -1;
for(int j=0;j<=4*N;j++){
if(use[(now+j)%(2*N)]==1) continue;
if(ocha_id!=-1 && v[(now+j)%(2*N)].second==1){
ans += del(now_d,v[ocha_id].first);
now_d = v[ocha_id].first;
now = ocha_id;
use[ocha_id] = 1;
sushi = false;
break;
}
if(v[(now+j)%(2*N)].second==-1){
ocha_id = (now+j)%(2*N);
if(cnt==2*N-1){
ans += del(now_d,v[ocha_id].first);
now_d = v[ocha_id].first;
now = ocha_id;
use[ocha_id] = 1;
sushi = false;
break;
}
}
}
}
cnt++;
}
cout << ans << endl;
}
sinsincoscos