結果

問題 No.808 Kaiten Sushi?
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-01 21:50:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 77,756 KB
実行使用メモリ 15,720 KB
最終ジャッジ日時 2023-10-12 01:21:20
合計ジャッジ時間 7,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
4,352 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 35 ms
5,720 KB
testcase_24 AC 27 ms
4,484 KB
testcase_25 AC 33 ms
7,780 KB
testcase_26 AC 33 ms
7,736 KB
testcase_27 AC 97 ms
13,764 KB
testcase_28 AC 28 ms
5,720 KB
testcase_29 AC 84 ms
12,916 KB
testcase_30 AC 51 ms
8,528 KB
testcase_31 AC 106 ms
13,532 KB
testcase_32 AC 99 ms
14,376 KB
testcase_33 AC 57 ms
8,476 KB
testcase_34 AC 63 ms
8,856 KB
testcase_35 AC 69 ms
15,720 KB
testcase_36 AC 56 ms
8,448 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 94 ms
14,176 KB
testcase_40 AC 26 ms
5,788 KB
testcase_41 AC 26 ms
5,704 KB
testcase_42 AC 80 ms
13,308 KB
testcase_43 AC 37 ms
7,712 KB
testcase_44 AC 57 ms
8,984 KB
testcase_45 AC 39 ms
7,740 KB
testcase_46 AC 21 ms
5,548 KB
testcase_47 AC 98 ms
14,300 KB
testcase_48 AC 110 ms
15,236 KB
testcase_49 AC 108 ms
14,036 KB
testcase_50 AC 104 ms
14,316 KB
testcase_51 AC 98 ms
14,532 KB
testcase_52 AC 72 ms
13,624 KB
testcase_53 AC 97 ms
14,136 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 2 ms
4,352 KB
testcase_56 AC 2 ms
4,356 KB
testcase_57 AC 28 ms
5,804 KB
testcase_58 AC 50 ms
6,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
ll N,L,X[100010],Y[100010];
vector<P> v,u;
int main(){
	cin >> N >> L;
	for(int i=1;i<=N;i++) cin >> X[i];
	for(int i=1;i<=N;i++) cin >> Y[i];
	for(int i=1;i<=N;i++){
		v.push_back(P(X[i],1));
		v.push_back(P(Y[i],-1));
	}
	sort(v.begin(),v.end());
	ll ma = 0,mi = 1e9,p = 0,q = 0;
	ll cnt = 0;
	for(int i=0;i<2*N;i++){
		cnt += v[i].second;
		if(ma<=cnt){
			ma = cnt; p = i;
		}
		if(mi>cnt){
			mi = cnt; q = i;
		}
	}
	if(mi>=0){
		cout << (ma-1)*L + v[p+1].first << endl;
		return 0;
	}
	bool sushi = false;
	for(int i=0;i<=q;i++){
		if(v[i].second==1){
			if(sushi) u.push_back(P(v[i].first+L,1));
			else sushi = true;
		}else{
			if(sushi && i==q) sushi = false;
			else u.push_back(P(v[i].first+L,-1));
		}
	}
	for(int i=q+1;i<2*N;i++) u.push_back(v[i]);
	sort(u.begin(),u.end());
	ma = 0; p = 0; cnt = 0;
	for(int i=0;i<(int) u.size();i++){
		cnt += u[i].second;
		if(ma<=cnt){
			ma = cnt; p = i;
		}
	}
	cout << (ma-1)*L + u[p+1].first << endl;
	return 0;
}
0