結果

問題 No.808 Kaiten Sushi?
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-01 23:02:32
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,453 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 69,344 KB
実行使用メモリ 11,364 KB
最終ジャッジ日時 2023-10-12 01:30:39
合計ジャッジ時間 35,253 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,364 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 13 ms
4,352 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 7 ms
4,352 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 11 ms
4,476 KB
testcase_16 AC 7 ms
4,352 KB
testcase_17 AC 25 ms
4,352 KB
testcase_18 AC 8 ms
4,352 KB
testcase_19 AC 3 ms
4,352 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 8 ms
4,352 KB
testcase_23 AC 37 ms
5,724 KB
testcase_24 AC 30 ms
4,860 KB
testcase_25 AC 32 ms
5,816 KB
testcase_26 AC 31 ms
5,740 KB
testcase_27 AC 1,897 ms
9,828 KB
testcase_28 AC 284 ms
4,660 KB
testcase_29 TLE -
testcase_30 AC 697 ms
6,072 KB
testcase_31 AC 1,502 ms
9,176 KB
testcase_32 AC 1,397 ms
9,260 KB
testcase_33 AC 949 ms
6,048 KB
testcase_34 AC 1,359 ms
6,440 KB
testcase_35 AC 1,251 ms
9,384 KB
testcase_36 AC 535 ms
5,840 KB
testcase_37 AC 2 ms
4,368 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 1,859 ms
9,784 KB
testcase_40 AC 242 ms
4,480 KB
testcase_41 AC 180 ms
4,664 KB
testcase_42 AC 1,482 ms
8,876 KB
testcase_43 AC 434 ms
5,704 KB
testcase_44 AC 894 ms
6,232 KB
testcase_45 AC 293 ms
5,696 KB
testcase_46 AC 123 ms
4,348 KB
testcase_47 TLE -
testcase_48 TLE -
testcase_49 AC 1,888 ms
10,768 KB
testcase_50 AC 1,851 ms
8,924 KB
testcase_51 TLE -
testcase_52 TLE -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
int use[100010] = {};
vector<P> v;

ll del(ll x,ll y){
	if(x<y) return y-x;
	else return L-x+y;
}

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 ans = 0,now_d = 0;
	int cnt = 0,now = 0;
	bool sushi = false;
	while(cnt<2*N){
		if(!sushi){
			for(int j=0;j<=4*N;j++){
				if(use[(now+j)%(2*N)]==1) continue;
				if(v[(now+j)%(2*N)].second==1){
					sushi = true;
					ans += del(now_d,v[(now+j)%(2*N)].first);
					now_d = v[(now+j)%(2*N)].first;
					use[(now+j)%(2*N)] = 1;
					now = (now+j)%(2*N);
					break;
				}
			}
		}else{
			int ocha_id = -1;
			for(int j=0;j<=4*N;j++){
				if(use[(now+j)%(2*N)]==1) continue;
				if(ocha_id!=-1 && v[(now+j)%(2*N)].second==1){
					ans += del(now_d,v[ocha_id].first);
					now_d = v[ocha_id].first;
					now = ocha_id;
					use[ocha_id] = 1;
					sushi = false;
					break;
				}
				if(v[(now+j)%(2*N)].second==-1){
					ocha_id = (now+j)%(2*N);
					if(cnt==2*N-1){
						ans += del(now_d,v[ocha_id].first);
						now_d = v[ocha_id].first;
						now = ocha_id;
						use[ocha_id] = 1;
						sushi = false;
						break;
					}
				}
			}
		}
		cnt++;
	}
	cout << ans << endl;
}
0