結果

問題 No.808 Kaiten Sushi?
ユーザー mtsdmtsd
提出日時 2019-03-22 22:00:14
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,204 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 90,900 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-09-19 05:22:00
合計ジャッジ時間 6,276 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<vector<pair<int,ll> > > g; 



int main(){
    int n;
    ll L;
    cin >> n >> L;
    set<ll> st,st2;
    rep(i,n){
        ll a;
        cin >> a;
        st.insert(a);
    }
    rep(i,n){
        ll a;
        cin >> a;
        st2.insert(a);
    }
    ll ans = 0;
    ll now = 0;
    bool flag = 0;
    while(st2.size()>0){
        if(!flag){
            auto p = st.lower_bound(now);
            ll next,next2;
            if(p==st.end()){
                next = *st.begin();
            }else{
                next = *p;
            }
            auto q = st2.lower_bound(next);
            if(q==st2.end()){
                next2 = L;
            }else{
                next2 = *q;
            }
            auto pp = st.lower_bound(next2);
            pp--;
            ll goal = *pp;
            if(now<goal){
                ans += goal-now;
            }else{
                ans += goal+L-now;
            }
            st.erase(*pp);
            now = goal;
            flag = 1;
        }else{
            auto p = st2.lower_bound(now);
            ll next,next2;
            if(p==st2.end()){
                next = *st2.begin();
            }else{
                next = *p;
            }
            auto q = st.lower_bound(next);
            if(q==st.end()){
                next2 = L;
            }else{
                next2 = *q;
            }
            auto pp = st2.lower_bound(next2);
            pp--;
            ll goal = *pp;
            if(now<goal){
                ans += goal-now;
            }else{
                ans += goal+L-now;
            }
            st2.erase(*pp);
            now = goal;
            flag = 0;
        }
    }
    cout << ans << endl;
    return 0;
}
0