結果

問題 No.808 Kaiten Sushi?
ユーザー heno239heno239
提出日時 2019-03-22 21:52:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 2,248 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 119,604 KB
実行使用メモリ 24,540 KB
最終ジャッジ日時 2023-10-19 09:02:16
合計ジャッジ時間 12,862 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,680 KB
testcase_01 AC 2 ms
5,684 KB
testcase_02 AC 2 ms
5,680 KB
testcase_03 AC 3 ms
5,680 KB
testcase_04 AC 2 ms
5,680 KB
testcase_05 AC 2 ms
5,680 KB
testcase_06 AC 3 ms
5,680 KB
testcase_07 AC 5 ms
5,928 KB
testcase_08 AC 5 ms
5,972 KB
testcase_09 AC 9 ms
6,172 KB
testcase_10 AC 7 ms
5,996 KB
testcase_11 AC 6 ms
5,908 KB
testcase_12 AC 7 ms
6,004 KB
testcase_13 AC 6 ms
5,948 KB
testcase_14 AC 4 ms
5,780 KB
testcase_15 AC 9 ms
6,124 KB
testcase_16 AC 8 ms
6,036 KB
testcase_17 AC 4 ms
5,828 KB
testcase_18 AC 3 ms
5,756 KB
testcase_19 AC 2 ms
5,712 KB
testcase_20 AC 3 ms
5,760 KB
testcase_21 AC 3 ms
5,716 KB
testcase_22 AC 3 ms
5,756 KB
testcase_23 AC 107 ms
12,884 KB
testcase_24 AC 87 ms
11,468 KB
testcase_25 AC 97 ms
12,432 KB
testcase_26 AC 91 ms
12,064 KB
testcase_27 AC 345 ms
21,144 KB
testcase_28 AC 89 ms
10,408 KB
testcase_29 AC 321 ms
20,352 KB
testcase_30 AC 201 ms
15,240 KB
testcase_31 AC 359 ms
21,880 KB
testcase_32 AC 408 ms
24,128 KB
testcase_33 AC 196 ms
15,136 KB
testcase_34 AC 231 ms
16,604 KB
testcase_35 AC 283 ms
18,912 KB
testcase_36 AC 193 ms
14,964 KB
testcase_37 AC 2 ms
5,680 KB
testcase_38 AC 2 ms
5,680 KB
testcase_39 AC 490 ms
22,800 KB
testcase_40 AC 87 ms
9,836 KB
testcase_41 AC 92 ms
10,328 KB
testcase_42 AC 367 ms
19,812 KB
testcase_43 AC 125 ms
11,864 KB
testcase_44 AC 279 ms
16,600 KB
testcase_45 AC 128 ms
11,876 KB
testcase_46 AC 66 ms
9,140 KB
testcase_47 AC 557 ms
24,540 KB
testcase_48 AC 567 ms
24,540 KB
testcase_49 AC 558 ms
24,540 KB
testcase_50 AC 553 ms
24,540 KB
testcase_51 AC 552 ms
24,540 KB
testcase_52 AC 232 ms
19,012 KB
testcase_53 AC 315 ms
24,112 KB
testcase_54 AC 3 ms
5,680 KB
testcase_55 AC 2 ms
5,680 KB
testcase_56 AC 3 ms
5,680 KB
testcase_57 AC 94 ms
12,172 KB
testcase_58 AC 159 ms
15,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
int n; ll l;
ll x[1 << 17], y[1 << 17];
ll dp[1 << 17];

set<ll> sx,sy;
void solve() {
	cin >> n >> l;
	rep(i, n) {
		cin >> x[i]; sx.insert(x[i]);
	}
	rep(i, n) {
		sx.insert(x[i] + l);
	}
	rep(i, n)cin >> y[i];
	rep(i, n) {
		sy.insert(y[i]); sy.insert(y[i] + l);
	}
	ll ans = 0; ll loc = 0;
	rep(i, n) {
		sx.insert(loc);
		auto itr = sx.find(loc);
		itr++;
		ll nex = *itr;
		ans += nex - loc;
		if (nex >= l)nex -= l;
		sx.erase(nex); sx.erase(nex + l); sx.erase(loc);
		loc = nex;
		//cout << ans << " a "<<loc<<endl;

		if (i == n - 1) {
			sy.insert(loc);
			itr = sy.find(loc);
			itr++;
			nex = *itr;
			ans += nex - loc;
			break;
		}
		sy.insert(loc);
		itr = sy.find(loc);
		itr++;
		nex = *itr; sy.erase(loc);

		if (nex >= l) {
			nex -= l; ans += l;
		}
		sx.insert(nex);
		auto itr2 = sx.find(nex);
		itr2++;
		//cout << "!!" << endl;
		ll nenex = *itr2; sx.erase(nex);
		//cout << "!?" << endl;
		if (nenex < l) {
			nenex += l; ans -= l;
		}
		sy.insert(nenex);
		auto itr3 = sy.find(nenex);
		//cout << "?" << endl;
		itr3--;
		nex = *itr3; sy.erase(nenex);

		ans += nex - loc;
		if (nex >= l)nex -= l;
		sy.erase(nex); sy.erase(nex + l);
		loc = nex;
		//cout << ans << " a " << loc << endl;
	}
	/*if (ans < l) {
		if (y[n - 1] > ans) {
			ans += y[n - 1];
		}
	}*/
	cout << ans << endl;
}
int main() {
	solve();
	//stop
	return 0;
}
0