結果
| 問題 |
No.808 Kaiten Sushi?
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-06-07 00:53:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 146 ms / 2,000 ms |
| コード長 | 1,341 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 89,532 KB |
| 実行使用メモリ | 14,336 KB |
| 最終ジャッジ日時 | 2024-12-23 14:32:22 |
| 合計ジャッジ時間 | 5,175 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
ll N, L;
ll x[100000];
ll y[100000];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
ll cur = 0;
ll ans = 0;
set<ll> stx, sty;
cin >> N >> L;
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]);
}
cur = x[0];
for(int i = 0; i < N; i++){
// sushi
auto p = sty.upper_bound(cur);
if(p == sty.end()){
p = sty.upper_bound(0);
}
auto q = stx.upper_bound(*p);
if(q == stx.begin()){
q = stx.end();
}
q--;
if(i == 0) ans += (*q+L)%L;
else ans += (*q-cur+L)%L;
cur = *q;
stx.erase(*q);
// cout << *q << ' ';
// tea
p = stx.upper_bound(cur);
if(p == stx.end()){
p = stx.upper_bound(0);
}
q = sty.upper_bound(*p);
if(q == sty.begin()){
q = sty.end();
}
q--;
ans += (*q-cur+L)%L;
cur = *q;
sty.erase(*q);
// cout << *q << endl;
}
cout << ans << endl;
}
milanis48663220