結果

問題 No.808 Kaiten Sushi?
ユーザー square1001square1001
提出日時 2019-03-22 21:40:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 72,856 KB
実行使用メモリ 13,004 KB
最終ジャッジ日時 2023-10-19 06:38:37
合計ジャッジ時間 8,086 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 4 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 56 ms
7,236 KB
testcase_24 AC 45 ms
6,524 KB
testcase_25 AC 50 ms
7,008 KB
testcase_26 AC 48 ms
6,824 KB
testcase_27 AC 155 ms
11,364 KB
testcase_28 AC 43 ms
5,996 KB
testcase_29 AC 145 ms
10,968 KB
testcase_30 AC 87 ms
8,412 KB
testcase_31 AC 165 ms
11,728 KB
testcase_32 AC 189 ms
12,808 KB
testcase_33 AC 92 ms
8,360 KB
testcase_34 AC 103 ms
9,096 KB
testcase_35 AC 129 ms
10,248 KB
testcase_36 AC 89 ms
8,276 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 208 ms
12,168 KB
testcase_40 AC 39 ms
5,712 KB
testcase_41 AC 43 ms
5,956 KB
testcase_42 AC 162 ms
10,700 KB
testcase_43 AC 59 ms
6,724 KB
testcase_44 AC 115 ms
9,092 KB
testcase_45 AC 59 ms
6,732 KB
testcase_46 AC 32 ms
5,364 KB
testcase_47 AC 230 ms
13,004 KB
testcase_48 AC 230 ms
13,004 KB
testcase_49 AC 226 ms
13,004 KB
testcase_50 AC 228 ms
13,004 KB
testcase_51 AC 228 ms
13,004 KB
testcase_52 AC 107 ms
10,296 KB
testcase_53 AC 150 ms
12,800 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 51 ms
6,880 KB
testcase_58 AC 88 ms
8,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <set>
#include <iostream>
using namespace std;
int main() {
	int N, L;
	cin >> N >> L;
	set<int> s, t;
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		s.insert(x);
	}
	for (int i = 0; i < N; ++i) {
		int y;
		cin >> y;
		t.insert(y);
	}
	long long pos = 0;
	for (int i = 0; i < N; ++i) {
		set<int>::iterator it = s.lower_bound(pos % L);
		if (it != s.end()) pos += *it - pos % L, s.erase(it);
		else pos += *s.begin() % L - pos % L + L, s.erase(s.begin());
		if (i + 1 == N) {
			pos += (*t.begin() - pos % L + L) % L;
		}
		else {
			long long nxt = pos;
			it = t.lower_bound(nxt % L);
			if (it != t.end()) nxt += *it - nxt % L;
			else nxt += *t.begin() - nxt % L + L;
			it = s.lower_bound(nxt % L);
			if (it != s.end()) nxt += *it - nxt % L;
			else nxt += *s.begin() - nxt % L + L;
			it = t.lower_bound(nxt % L);
			if (it != t.begin()) --it, pos = nxt - (nxt % L - *it), t.erase(it);
			else it = --t.end(), pos = nxt - (nxt % L - *it + L), t.erase(it);
		}
	}
	cout << pos << endl;
	return 0;
}
0