結果

問題 No.808 Kaiten Sushi?
ユーザー gazelle
提出日時 2019-03-22 22:11:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,551 bytes
コンパイル時間 1,314 ms
コンパイル使用メモリ 120,508 KB
最終ジャッジ日時 2025-01-06 23:52:36
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 22 TLE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, l;
	cin >> n >> l;
	set<ll> xx, yy;
	REP(i, n) {
		ll tmp;
		cin >> tmp;
		xx.insert(tmp);
	}
	REP(i, n) {
		ll tmp;
		cin >> tmp;
		yy.insert(tmp);
	}
	ll lb = 0, ub = INF * INF;
	while(ub - lb > 1) {
		ll m = (ub + lb) / 2;
		ll pos = m % l, tmp = 0;
		set<ll> x = xx, y = yy;
		REP(i, n) {
			auto ite = y.upper_bound(pos);
			if(ite == y.begin()) {
				tmp += pos + 1;
				pos = l - 1;
				ite = y.end();
				ite--;
			} else ite--;
			tmp += pos - *ite;
			pos = *ite;
			y.erase(ite);
			ite = x.upper_bound(pos);
			if(ite == x.begin()) {
				tmp += l - pos;
				pos = 0;
				ite = x.end();
				ite--;
			} else ite--;
			tmp += pos - *ite;
			pos = *ite;
			x.erase(ite);
		}
		if(tmp > m) lb = m;
		else ub = m;
	}
	cout << ub << endl;
	return 0;
}

/* --------------------------------------- */
0