結果

問題 No.808 Kaiten Sushi?
ユーザー startcppstartcpp
提出日時 2019-03-22 23:21:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,342 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 66,872 KB
実行使用メモリ 18,748 KB
最終ジャッジ日時 2023-10-19 10:46:48
合計ジャッジ時間 17,721 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 27 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 544 ms
7,632 KB
testcase_26 AC 496 ms
7,420 KB
testcase_27 TLE -
testcase_28 AC 456 ms
6,452 KB
testcase_29 TLE -
testcase_30 AC 1,367 ms
9,272 KB
testcase_31 TLE -
testcase_32 TLE -
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 <algorithm>
#include <set>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, l;
int x[100000];
int y[100000];

//lastについて狭義凸な関数
int simurate(int last) {
	set<int> A;
	set<int> B;
	set<int>::iterator it;
	int i;
	
	rep(i, n) if (i > 0) A.insert(x[i]);
	rep(i, n) if (i != last) B.insert(y[i]);
	
	int now = x[0];
	int ret = 0;
	
	rep(i, 2 * n - 2) {
		if (i % 2 == 0) {
			it = B.lower_bound(now);
			if (it == B.end())
				it = B.lower_bound(0);
			int nxt = (*it);
			if (nxt > now) {
				ret += nxt - now;
			}
			else {
				ret += l + nxt - now;
			}
			B.erase(it);
			now = nxt;
		}
		else {
			it = A.lower_bound(now);
			if (it == A.end())
				it = A.lower_bound(0);
			int nxt = (*it);
			if (nxt > now) {
				ret += nxt - now;
			}
			else {
				ret += l + nxt - now;
			}
			A.erase(it);
			now = nxt;
		}
	}
	
	if (y[last] > now) ret += y[last] - now;
	else ret += l + y[last] - now;
	ret += x[0];
	return ret;
}

signed main() {
	int i;
	
	cin >> n >> l;
	rep(i, n) cin >> x[i];
	rep(i, n) cin >> y[i];
	
	int st = 0, ed = n - 1, mid;
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		int sub = simurate(mid + 1) - simurate(mid);
		if (sub < 0) st = mid;
		else ed = mid;
	}
	cout << min(simurate(0), simurate(st + 1)) << endl;
	return 0;
}
0