結果

問題 No.808 Kaiten Sushi?
ユーザー 沙耶花沙耶花
提出日時 2020-12-08 14:19:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,652 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 220,840 KB
実行使用メモリ 41,792 KB
最終ジャッジ日時 2023-10-17 17:13:22
合計ジャッジ時間 12,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 42 ms
4,712 KB
testcase_08 AC 49 ms
4,732 KB
testcase_09 AC 100 ms
5,796 KB
testcase_10 AC 57 ms
4,752 KB
testcase_11 AC 41 ms
4,712 KB
testcase_12 AC 60 ms
4,760 KB
testcase_13 AC 48 ms
4,712 KB
testcase_14 AC 18 ms
4,348 KB
testcase_15 AC 92 ms
5,768 KB
testcase_16 AC 65 ms
4,788 KB
testcase_17 AC 35 ms
4,348 KB
testcase_18 AC 17 ms
4,348 KB
testcase_19 AC 8 ms
4,348 KB
testcase_20 AC 18 ms
4,348 KB
testcase_21 AC 9 ms
4,348 KB
testcase_22 AC 17 ms
4,348 KB
testcase_23 AC 1,949 ms
41,792 KB
testcase_24 AC 1,491 ms
25,364 KB
testcase_25 AC 1,820 ms
41,000 KB
testcase_26 AC 1,710 ms
40,472 KB
testcase_27 TLE -
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 <bits/stdc++.h>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

vector<int> op(vector<int> a,vector<int> b){
	rep(i,2)a[i] = max(a[i],b[i]);
	return a;
}

vector<int> e(){
	return vector<int>(2,-1);
}

int main(){

	int N;
	cin>>N;
	
	long long L;
	cin>>L;
	
	vector<pair<long long,int>> V(2*N);
	rep(i,N){
		scanf("%lld",&V[i].first);
		V[i].second = 0;
	}
	
	rep(i,N){
		scanf("%lld",&V[i+N].first);
		V[i+N].second = 1;
	}
	
	sort(V.begin(),V.end());
	
	segtree<vector<int>,op,e> seg(4*N);
	
	rep(i,2*N){
		vector<int> temp(2,-1);
		temp[V[i].second] = i;
		seg.set(i,temp);
		temp[V[i].second] = 2*N+i;
		seg.set(2*N+i,temp);
	}
	
	vector<int> ans;
	int now = 0;
	
	while(ans.size()!=2*N){
		int temp = 0;
		if(ans.size()>0)temp = ans.back();
		
		int ok = 4*N,ng = temp;
		while(ok-ng>1){
			int mid = (ok+ng)/2;
			vector<int> ret = seg.prod(temp,mid);
			if(ret[now]==-1)ng = mid;
			else ok = mid;
		}
		int x;
		{
			vector<int> ret = seg.prod(temp,ok);
			x = ret[now^1];
		}
		ok = temp,ng = 4*N;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			vector<int> ret = seg.prod(temp,mid);
			if(ret[now^1]<=x)ok = mid;
			else ng = mid;
		}
		
		vector<int> ret = seg.prod(temp,ok);
		x = ret[now]%(2*N);
		ans.push_back(x);
		seg.set(x,vector<int>(2,-1));
		seg.set(x+2*N,vector<int>(2,-1));
		
		now ^= 1;
	}
	
	
	long long Ans = 0LL;
	
	rep(i,2*N){
		if(i==0)Ans += V[ans[i]].first;
		else{
			long long temp = V[ans[i]].first - V[ans[i-1]].first;
			if(temp<0)temp += L;
			Ans += temp;
		}
	}
	
	cout<<Ans<<endl;
		
	
	return 0;
}
0