結果

問題 No.808 Kaiten Sushi?
ユーザー tempura_pptempura_pp
提出日時 2019-03-22 21:43:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 544 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 104,224 KB
実行使用メモリ 31,616 KB
最終ジャッジ日時 2024-09-19 04:01:40
合計ジャッジ時間 11,252 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 121 ms
14,336 KB
testcase_24 AC 96 ms
12,160 KB
testcase_25 AC 104 ms
13,568 KB
testcase_26 AC 98 ms
13,056 KB
testcase_27 AC 319 ms
26,624 KB
testcase_28 AC 85 ms
10,496 KB
testcase_29 AC 301 ms
25,472 KB
testcase_30 AC 184 ms
17,792 KB
testcase_31 AC 338 ms
27,648 KB
testcase_32 AC 384 ms
30,848 KB
testcase_33 AC 184 ms
17,664 KB
testcase_34 AC 216 ms
19,840 KB
testcase_35 AC 268 ms
23,168 KB
testcase_36 AC 179 ms
17,408 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 452 ms
29,056 KB
testcase_40 AC 85 ms
9,728 KB
testcase_41 AC 87 ms
10,496 KB
testcase_42 AC 361 ms
24,704 KB
testcase_43 AC 120 ms
12,800 KB
testcase_44 AC 271 ms
19,712 KB
testcase_45 AC 123 ms
12,800 KB
testcase_46 AC 61 ms
8,704 KB
testcase_47 AC 544 ms
31,488 KB
testcase_48 AC 538 ms
31,616 KB
testcase_49 AC 537 ms
31,616 KB
testcase_50 AC 539 ms
31,616 KB
testcase_51 AC 542 ms
31,616 KB
testcase_52 AC 240 ms
23,424 KB
testcase_53 AC 342 ms
30,848 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 106 ms
13,184 KB
testcase_58 AC 181 ms
18,432 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