結果

問題 No.808 Kaiten Sushi?
ユーザー leaf_1415leaf_1415
提出日時 2019-03-22 22:08:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 1,212 ms
コンパイル使用メモリ 65,140 KB
実行使用メモリ 813,624 KB
最終ジャッジ日時 2023-10-19 09:24:33
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 RE -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#define llint long long 

using namespace std;

llint n, l;
set<llint> S, T;

llint dist(llint s, llint t)
{
	if(s > t) return t+l - s;
	else return t-s;
}

set<llint>::iterator succ(set<llint> &S, llint x)
{
	auto p = S.upper_bound(x);
	if(p == S.end()) p = S.begin();
	return p;
}
set<llint>::iterator pred(set<llint> &S, llint x)
{
	auto p = S.lower_bound(x);
	if(p == S.begin()) p = S.end();
	p--;
	return p;
}

int main(void)
{
	cin >> n >> l;
	llint x;
	for(int i = 1; i <= n; i++) cin >> x, S.insert(x);
	for(int i = 1; i <= n; i++) cin >> x, T.insert(x);
	
	llint ans = 0, pos = 0;
	for(int i = 1; i < n; i++){
		auto p = succ(S, pos);
		p = succ(T, *p);
		p = pred(S, *p);
		ans += dist(pos, *p);
		pos = *p;
		S.erase(p);
		
		p = succ(T, pos);
		p = succ(S, *p);
		p = pred(T, *p);
		ans += dist(pos, *p);
		pos = *p;
		T.erase(p);
	}
	auto p = succ(S, pos);
	ans += dist(pos, *p);
	pos = *p;
	S.erase(p);
	
	p = succ(T, pos);
	ans += dist(pos, *p);
	pos = *p;
	S.erase(p);
	
	cout << ans << endl;
	return 0;
}
0