結果

問題 No.808 Kaiten Sushi?
ユーザー mtsdmtsd
提出日時 2019-03-22 22:00:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,204 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 92,072 KB
実行使用メモリ 13,004 KB
最終ジャッジ日時 2023-10-19 09:09:49
合計ジャッジ時間 6,993 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 56 ms
7,236 KB
testcase_24 AC 45 ms
6,524 KB
testcase_25 AC 51 ms
7,008 KB
testcase_26 AC 49 ms
6,824 KB
testcase_27 AC 181 ms
11,364 KB
testcase_28 AC 48 ms
5,996 KB
testcase_29 AC 169 ms
10,968 KB
testcase_30 AC 105 ms
8,412 KB
testcase_31 AC 188 ms
11,728 KB
testcase_32 WA -
testcase_33 AC 106 ms
8,360 KB
testcase_34 AC 119 ms
9,096 KB
testcase_35 WA -
testcase_36 AC 102 ms
8,276 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 231 ms
12,168 KB
testcase_40 AC 45 ms
5,712 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 68 ms
6,724 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 38 ms
5,364 KB
testcase_47 WA -
testcase_48 AC 263 ms
13,004 KB
testcase_49 AC 260 ms
13,004 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 119 ms
10,296 KB
testcase_53 AC 166 ms
12,800 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 51 ms
6,880 KB
testcase_58 AC 89 ms
8,616 KB
権限があれば一括ダウンロードができます

ソースコード

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