結果

問題 No.808 Kaiten Sushi?
ユーザー startcppstartcpp
提出日時 2019-03-22 23:34:03
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,170 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 67,020 KB
実行使用メモリ 11,920 KB
最終ジャッジ日時 2023-10-19 10:53:30
合計ジャッジ時間 16,190 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 381 ms
4,348 KB
testcase_08 AC 532 ms
4,348 KB
testcase_09 TLE -
testcase_10 AC 985 ms
4,348 KB
testcase_11 AC 506 ms
4,348 KB
testcase_12 AC 1,026 ms
4,348 KB
testcase_13 AC 703 ms
4,348 KB
testcase_14 AC 96 ms
4,348 KB
testcase_15 TLE -
testcase_16 AC 1,269 ms
4,348 KB
testcase_17 AC 154 ms
4,348 KB
testcase_18 AC 44 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 48 ms
4,348 KB
testcase_21 AC 12 ms
4,348 KB
testcase_22 AC 41 ms
4,348 KB
testcase_23 TLE -
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 <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];

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 ans = 1e+15;
	rep(i, n) {
		ans = min(ans, simurate(i));
	}
	cout << ans << endl;
	return 0;
}
0