結果

問題 No.808 Kaiten Sushi?
ユーザー beetbeet
提出日時 2019-03-22 22:22:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 1,629 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 207,860 KB
実行使用メモリ 12,940 KB
最終ジャッジ日時 2023-10-19 09:42:02
合計ジャッジ時間 8,077 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 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 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
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,172 KB
testcase_24 AC 45 ms
6,460 KB
testcase_25 AC 50 ms
6,944 KB
testcase_26 AC 48 ms
6,760 KB
testcase_27 AC 159 ms
11,300 KB
testcase_28 AC 45 ms
5,932 KB
testcase_29 AC 150 ms
10,904 KB
testcase_30 AC 90 ms
8,348 KB
testcase_31 AC 165 ms
11,664 KB
testcase_32 AC 188 ms
12,744 KB
testcase_33 AC 91 ms
8,296 KB
testcase_34 AC 103 ms
9,032 KB
testcase_35 AC 132 ms
10,184 KB
testcase_36 AC 92 ms
8,212 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 209 ms
12,104 KB
testcase_40 AC 39 ms
5,648 KB
testcase_41 AC 44 ms
5,892 KB
testcase_42 AC 161 ms
10,636 KB
testcase_43 AC 59 ms
6,660 KB
testcase_44 AC 116 ms
9,028 KB
testcase_45 AC 60 ms
6,668 KB
testcase_46 AC 32 ms
5,300 KB
testcase_47 AC 224 ms
12,940 KB
testcase_48 AC 226 ms
12,940 KB
testcase_49 AC 223 ms
12,940 KB
testcase_50 AC 221 ms
12,940 KB
testcase_51 AC 218 ms
12,940 KB
testcase_52 AC 108 ms
10,232 KB
testcase_53 AC 149 ms
12,736 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 50 ms
6,816 KB
testcase_58 AC 88 ms
8,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,l;
  cin>>n>>l;
  set<Int> sx,sy;
  for(Int i=0;i<n;i++){
    Int x;
    cin>>x;
    sx.emplace(x);
  }
  for(Int i=0;i<n;i++){
    Int y;
    cin>>y;
    sy.emplace(y);
  }
  Int time=0;
  while(!sx.empty()){
    {
      Int t=time%l;
      auto it=sx.upper_bound(t);
      if(it==sx.end()){           
        time+=l-t;
        time+=*sx.begin();
        sx.erase(sx.begin());
      }else{      
        time+=*it-t;
        sx.erase(it);
      }
    }
    if(sx.empty()){
      Int t=time%l;
      Int u=*sy.begin();
      if(t<u){
        time+=u-t;
      }else{
        time+=l-t;
        time+=u;
      }
      break;
    }
    {
      Int t=time%l;
      Int u=0;      
      {
        auto it=sy.upper_bound(t);
        if(it==sy.end()) u=*sy.begin();
        else u=*it;
      }
      {
        auto it=sx.upper_bound(u);
        if(it==sx.end()) u=*sx.begin();
        else u=*it;        
      }
      auto it=sy.upper_bound(u);
      if(it==sy.begin()){
        if(t<*sy.rbegin()){
          time+=*sy.rbegin()-t;
        }else{
          time+=l-t;
          time+=*sy.rbegin();
        }
        sy.erase(--sy.end());        
      }else{        
        --it;
        if(t<*it){
          time+=*it-t;
        }else{
          time+=l-t;
          time+=*it;
        }
        sy.erase(it);
      }
    }
  }  
  cout<<time<<endl;
  return 0;
}
0