結果

問題 No.808 Kaiten Sushi?
ユーザー chocoruskchocorusk
提出日時 2019-03-23 00:46:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,580 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 108,856 KB
実行使用メモリ 14,612 KB
最終ジャッジ日時 2023-10-19 11:24:50
合計ジャッジ時間 9,651 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 7 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 73 ms
7,876 KB
testcase_24 AC 58 ms
7,044 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 140 ms
9,188 KB
testcase_34 AC 161 ms
10,048 KB
testcase_35 WA -
testcase_36 AC 133 ms
9,088 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 366 ms
13,632 KB
testcase_40 AC 62 ms
6,096 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 89 ms
7,276 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 47 ms
5,692 KB
testcase_47 WA -
testcase_48 AC 428 ms
14,596 KB
testcase_49 AC 441 ms
14,596 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 1 ms
4,348 KB
testcase_57 AC 68 ms
7,460 KB
testcase_58 AC 117 ms
9,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
int n; ll l;
ll x[100001], y[100001];
int main()
{
    cin>>n>>l;
    set<ll> stx, sty;
    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]);
    }
    ll r=0;
    int ct=0;
    while(!stx.empty() && !sty.empty()){
        auto itrx=stx.lower_bound(r);
        if(itrx==stx.end()){
            ct++;
            r=*stx.begin();
        }else{
            r=*itrx;
        }
        stx.erase(r);
        if(stx.empty()){
            if(r>*sty.begin()) ct++;
            r=*sty.begin();
            sty.erase(sty.begin());
            break;
        }
        ll r2;
        auto itry=sty.lower_bound(r);
        if(itry==sty.end()) r2=*sty.begin();
        else r2=*itry;
        itrx=stx.lower_bound(r2);
        ll r1;
        if(itrx==stx.end()) r1=*stx.begin();
        else r1=*itrx;
        itry=sty.lower_bound(r1);
        if(itry==sty.begin()){
            itry=sty.end(); itry--;
        }else{
            itry--;
        }
        if(*itry<r) ct++;
        r=*itry;
        sty.erase(itry);
    }
    ll ans=(ll)ct*l+r;
    r=0; ct=0;
    for(int i=0; i<n; i++){
        swap(x[i], y[i]);
        stx.insert(x[i]); sty.insert(y[i]);
    }
    while(!stx.empty() && !sty.empty()){
        auto itrx=stx.lower_bound(r);
        if(itrx==stx.end()){
            ct++;
            r=*stx.begin();
        }else{
            r=*itrx;
        }
        stx.erase(r);
        if(stx.empty()){
            if(r>*sty.begin()) ct++;
            r=*sty.begin();
            sty.erase(sty.begin());
            break;
        }
        ll r2;
        auto itry=sty.lower_bound(r);
        if(itry==sty.end()) r2=*sty.begin();
        else r2=*itry;
        itrx=stx.lower_bound(r2);
        ll r1;
        if(itrx==stx.end()) r1=*stx.begin();
        else r1=*itrx;
        itry=sty.lower_bound(r1);
        if(itry==sty.begin()){
            itry=sty.end(); itry--;
        }else{
            itry--;
        }
        if(*itry<r) ct++;
        r=*itry;
        sty.erase(itry);
    }
    ans=min(ans, (ll)ct*l+r);
    cout<<ans<<endl;
    return 0;
}
0