結果

問題 No.808 Kaiten Sushi?
ユーザー addeight2addeight2
提出日時 2019-03-23 16:05:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 1,047 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 174,068 KB
実行使用メモリ 18,480 KB
最終ジャッジ日時 2023-10-23 21:37:07
合計ジャッジ時間 10,814 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 4 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 45 ms
9,464 KB
testcase_24 AC 35 ms
7,588 KB
testcase_25 AC 40 ms
9,196 KB
testcase_26 AC 40 ms
8,988 KB
testcase_27 AC 143 ms
16,576 KB
testcase_28 AC 38 ms
6,972 KB
testcase_29 AC 132 ms
16,112 KB
testcase_30 AC 81 ms
10,840 KB
testcase_31 AC 149 ms
16,996 KB
testcase_32 AC 172 ms
18,256 KB
testcase_33 AC 83 ms
10,780 KB
testcase_34 AC 95 ms
11,636 KB
testcase_35 AC 118 ms
15,276 KB
testcase_36 AC 78 ms
10,676 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 177 ms
17,512 KB
testcase_40 AC 34 ms
6,636 KB
testcase_41 AC 38 ms
6,920 KB
testcase_42 AC 144 ms
15,796 KB
testcase_43 AC 57 ms
8,868 KB
testcase_44 AC 104 ms
11,628 KB
testcase_45 AC 54 ms
8,876 KB
testcase_46 AC 29 ms
6,232 KB
testcase_47 AC 197 ms
18,480 KB
testcase_48 AC 207 ms
18,480 KB
testcase_49 AC 201 ms
18,480 KB
testcase_50 AC 196 ms
18,480 KB
testcase_51 AC 200 ms
18,480 KB
testcase_52 AC 82 ms
15,332 KB
testcase_53 AC 113 ms
18,248 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 37 ms
9,048 KB
testcase_58 AC 60 ms
11,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5;
typedef pair<ll,ll> P;
ll N,L,X[MAX_N],Y[MAX_N];
ll f(){
	set<ll> st[2];
	REP(i,N)st[0].insert(X[i]);
	REP(i,N)st[1].insert(Y[i]);
	ll x;
	vector<P> vec;
	REP(i,N){
		vec.push_back(P(X[i],0));
	}
	REP(i,N){
		vec.push_back(P(Y[i],1));
	}
	sort(vec.begin(),vec.end());
	{
		ll inx=0;
		while(vec[inx].second==1)inx++;
		while(inx<N*2 && vec[inx].second==0)inx++;
		inx--;
		x=vec[inx].first;
	}
	ll ret=x;
	REP(i,N*2-1){
		ll typ=(i%2==0 ? 0 : 1);
		auto ite=st[typ].upper_bound(x);
		if(ite==st[typ].end()){
			ite=st[typ].begin();
		}
		ll typ2=1-typ;
		auto ite2=st[typ2].upper_bound(*ite);
		if(ite2==st[typ2].begin()){
			ite2=st[typ2].end();
		}
		ite2--;
		st[typ].erase(x);
		ll a=*ite2-x;
		if(a<0){
			a+=L;
		}
		ret+=a;
		x=*ite2;
	}
	return ret;
	
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>L;
	REP(i,N)cin>>X[i];
	REP(i,N)cin>>Y[i];
	cout<<f()<<endl;
}
0