結果

問題 No.808 Kaiten Sushi?
ユーザー tempura_pptempura_pp
提出日時 2019-03-22 21:43:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 104,428 KB
実行使用メモリ 31,788 KB
最終ジャッジ日時 2023-10-19 07:43:25
合計ジャッジ時間 11,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 9 ms
4,408 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 120 ms
14,480 KB
testcase_24 AC 95 ms
12,352 KB
testcase_25 AC 103 ms
13,800 KB
testcase_26 AC 98 ms
13,244 KB
testcase_27 AC 323 ms
26,868 KB
testcase_28 AC 85 ms
10,764 KB
testcase_29 AC 301 ms
25,680 KB
testcase_30 AC 183 ms
18,008 KB
testcase_31 AC 339 ms
27,956 KB
testcase_32 AC 385 ms
31,192 KB
testcase_33 AC 182 ms
17,856 KB
testcase_34 AC 215 ms
20,060 KB
testcase_35 AC 272 ms
23,520 KB
testcase_36 AC 183 ms
17,600 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 475 ms
29,280 KB
testcase_40 AC 85 ms
9,908 KB
testcase_41 AC 86 ms
10,644 KB
testcase_42 AC 357 ms
24,868 KB
testcase_43 AC 120 ms
12,948 KB
testcase_44 AC 281 ms
20,052 KB
testcase_45 AC 121 ms
12,964 KB
testcase_46 AC 62 ms
8,864 KB
testcase_47 AC 539 ms
31,788 KB
testcase_48 AC 531 ms
31,788 KB
testcase_49 AC 529 ms
31,788 KB
testcase_50 AC 535 ms
31,788 KB
testcase_51 AC 538 ms
31,788 KB
testcase_52 AC 241 ms
23,668 KB
testcase_53 AC 338 ms
31,168 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 106 ms
13,408 KB
testcase_58 AC 179 ms
18,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    ll T;
    cin>>T;
    set<ll> sushi,tea;
    rep(i,n){
        ll x;
        cin>>x;
        sushi.insert(x);
        sushi.insert(T+x);
        sushi.insert(2*T+x);
    }
    rep(i,n){
        ll x;
        cin>>x;
        tea.insert(x);
        tea.insert(T+x);
        tea.insert(2*T+x);
    }
    ll cur=0;
    int cnt=0;
    ll ans=0;
    while(1){
        auto itr=sushi.lower_bound(cur);
        ans+=*itr-cur;
        ll ret=*itr;
        if(ret>T)ret-=T;
        sushi.erase(ret);
        sushi.erase(ret+T);
        sushi.erase(ret+2*T);
        ll res=*tea.lower_bound(ret);
        if(cnt==n-1){
            ans+=res-ret;
            break;
        }
        ll nxt=*sushi.lower_bound(res);
        res=*prev(tea.lower_bound(nxt));
        ans+=res-ret;
        while(res>T)res-=T;
        tea.erase(res);
        tea.erase(res+T);
        tea.erase(res+2*T);
        cur=res;
        ++cnt;
    }
    cout<<ans<<endl;
    return 0;
}
0