結果

問題 No.808 Kaiten Sushi?
ユーザー leaf_1415leaf_1415
提出日時 2019-03-22 22:10:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 65,120 KB
実行使用メモリ 12,932 KB
最終ジャッジ日時 2023-10-19 09:27:03
合計ジャッジ時間 7,986 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 3 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 4 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 3 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 54 ms
7,164 KB
testcase_24 AC 45 ms
6,452 KB
testcase_25 AC 50 ms
6,936 KB
testcase_26 AC 48 ms
6,752 KB
testcase_27 AC 164 ms
11,292 KB
testcase_28 AC 45 ms
5,924 KB
testcase_29 AC 153 ms
10,896 KB
testcase_30 AC 94 ms
8,340 KB
testcase_31 AC 171 ms
11,656 KB
testcase_32 AC 200 ms
12,736 KB
testcase_33 AC 96 ms
8,288 KB
testcase_34 AC 108 ms
9,024 KB
testcase_35 AC 139 ms
10,176 KB
testcase_36 AC 93 ms
8,204 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 215 ms
12,096 KB
testcase_40 AC 41 ms
5,640 KB
testcase_41 AC 46 ms
5,884 KB
testcase_42 AC 170 ms
10,628 KB
testcase_43 AC 62 ms
6,652 KB
testcase_44 AC 121 ms
9,020 KB
testcase_45 AC 63 ms
6,660 KB
testcase_46 AC 34 ms
5,292 KB
testcase_47 AC 242 ms
12,932 KB
testcase_48 AC 236 ms
12,932 KB
testcase_49 AC 236 ms
12,932 KB
testcase_50 AC 253 ms
12,932 KB
testcase_51 AC 235 ms
12,932 KB
testcase_52 AC 109 ms
10,224 KB
testcase_53 AC 152 ms
12,728 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 47 ms
6,808 KB
testcase_58 AC 82 ms
8,544 KB
権限があれば一括ダウンロードができます

ソースコード

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;
	T.erase(p);
	
	cout << ans << endl;
	return 0;
}
0