結果

問題 No.808 Kaiten Sushi?
ユーザー 👑 kmjpkmjp
提出日時 2019-03-22 21:53:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 593 ms / 2,000 ms
コード長 1,474 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 177,380 KB
実行使用メモリ 41,176 KB
最終ジャッジ日時 2023-10-19 09:04:06
合計ジャッジ時間 13,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 9 ms
4,672 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 8 ms
4,576 KB
testcase_16 AC 7 ms
4,400 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 153 ms
18,104 KB
testcase_24 AC 119 ms
15,264 KB
testcase_25 AC 127 ms
17,196 KB
testcase_26 AC 121 ms
16,456 KB
testcase_27 AC 357 ms
34,624 KB
testcase_28 AC 95 ms
13,148 KB
testcase_29 AC 333 ms
33,036 KB
testcase_30 AC 209 ms
22,808 KB
testcase_31 AC 379 ms
36,072 KB
testcase_32 AC 431 ms
40,384 KB
testcase_33 AC 208 ms
22,604 KB
testcase_34 AC 243 ms
25,544 KB
testcase_35 AC 303 ms
30,160 KB
testcase_36 AC 204 ms
22,264 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 555 ms
37,836 KB
testcase_40 AC 95 ms
12,004 KB
testcase_41 AC 103 ms
12,988 KB
testcase_42 AC 403 ms
31,956 KB
testcase_43 AC 134 ms
16,064 KB
testcase_44 AC 328 ms
25,532 KB
testcase_45 AC 136 ms
16,080 KB
testcase_46 AC 70 ms
10,616 KB
testcase_47 AC 590 ms
41,176 KB
testcase_48 AC 591 ms
41,176 KB
testcase_49 AC 589 ms
41,176 KB
testcase_50 AC 593 ms
41,176 KB
testcase_51 AC 589 ms
41,176 KB
testcase_52 AC 297 ms
30,352 KB
testcase_53 AC 423 ms
40,356 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 132 ms
16,672 KB
testcase_58 AC 216 ms
23,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll L;
set<ll> A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L;
	FOR(i,N) {
		cin>>x;
		A.insert(x);
		A.insert(L+x);
		A.insert(2*L+x);
		A.insert(3*L+x);
	}
	FOR(i,N) {
		cin>>x;
		B.insert(x);
		B.insert(L+x);
		B.insert(2*L+x);
		B.insert(3*L+x);
	}
	
	ll cur=0;
	ll ret=0;
	while(A.size()) {
		cur%=L;
		// 次の寿司
		auto it=A.lower_bound(cur);
		ret+=*it-cur;
		cur=*it%L;
		A.erase(cur);
		A.erase(L+cur);
		A.erase(2*L+cur);
		A.erase(3*L+cur);
		if(A.empty()) {
			ret+=*B.lower_bound(cur)-cur;
		}
		else {
			ll nexB=*B.lower_bound(cur);
			ll nexA=*A.lower_bound(nexB);
			auto it=B.lower_bound(nexA);
			it--;
			ret+=*it-cur;
			cur=*it%L;
			B.erase(cur);
			B.erase(L+cur);
			B.erase(2*L+cur);
			B.erase(3*L+cur);
		}
		
		
	}
	
	cout<<ret<<endl;
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0