結果

問題 No.953 席
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2019-12-19 16:18:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 2,762 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 200,776 KB
実行使用メモリ 20,676 KB
最終ジャッジ日時 2023-09-21 07:06:31
合計ジャッジ時間 14,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 376 ms
4,548 KB
testcase_03 AC 358 ms
4,376 KB
testcase_04 AC 367 ms
4,380 KB
testcase_05 AC 315 ms
4,380 KB
testcase_06 AC 371 ms
4,572 KB
testcase_07 AC 441 ms
18,928 KB
testcase_08 AC 523 ms
12,724 KB
testcase_09 AC 388 ms
20,676 KB
testcase_10 AC 125 ms
8,044 KB
testcase_11 AC 361 ms
10,404 KB
testcase_12 AC 480 ms
9,456 KB
testcase_13 AC 495 ms
11,664 KB
testcase_14 AC 446 ms
7,888 KB
testcase_15 AC 422 ms
7,432 KB
testcase_16 AC 440 ms
7,800 KB
testcase_17 AC 406 ms
9,428 KB
testcase_18 AC 390 ms
8,424 KB
testcase_19 AC 442 ms
12,572 KB
testcase_20 AC 414 ms
8,344 KB
testcase_21 AC 366 ms
5,100 KB
testcase_22 AC 455 ms
9,612 KB
testcase_23 AC 399 ms
5,908 KB
testcase_24 AC 407 ms
6,008 KB
testcase_25 AC 507 ms
12,248 KB
testcase_26 AC 225 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

map<int, int> SeatToIdx;
map<int, int> IdxToSeat;

int main() {
	int n, k1, k2; cin >> n >> k1 >> k2;
	vector<tuple<int, int, int>> v(n);
	for(int i = 1; i <= n; ++i) {
		if(k1 < k2) {
			if(i <= k1) {
				v[i - 1] = make_tuple(abs(k1 - i), 1, i);
			} else {
				v[i - 1] = make_tuple(abs(k1 - i), 0, i);
			}
		} else {
			if(k1 <= i) {
				v[i - 1] = make_tuple(abs(k1 - i), 1, i);
			} else {
				v[i - 1] = make_tuple(abs(k1 - i), 0, i);
			}
		}
	}
	sort(v.begin(), v.end());
	for(int i = 0; i < n; ++i) {
		int _, __, seat;
		tie(_, __, seat) = v[i];
		SeatToIdx[seat] = i + 1;
		IdxToSeat[i + 1] = seat;
	}
	set<int> ok;
	set<int> notUsed;
	for(int i = 1; i <= n; ++i) ok.insert(i);
	for(int i = 1; i <= n; ++i) notUsed.insert(i);
	priority_queue<pair<int64_t, int>, vector<pair<int64_t, int>>, greater<pair<int64_t, int>>> pq;
	int q; cin >> q;
	int64_t wait = 0;
	while(q--) {
		int64_t a, b; cin >> a >> b;
		a = max(a, wait);
		while(pq.size()) {
			int64_t t, idx;
			tie(t, idx) = pq.top();
			if(t > a) {
				if(ok.empty()) {
					if(notUsed.empty()) {
						wait = t;
						a = max(a, wait);
						continue;
					}
				}
				break;
			}
			pq.pop();
			int seat = IdxToSeat[idx];
			bool left = true, right = true;
			if(SeatToIdx[seat - 1] != 0 and notUsed.find(SeatToIdx[seat - 1]) == notUsed.end()) {
				left = false;
			}
			if(SeatToIdx[seat + 1] != 0 and notUsed.find(SeatToIdx[seat + 1]) == notUsed.end()) {
				right = false;
			}
			if(left and right) {
				ok.insert(idx);
			}
			notUsed.insert(idx);
			if(SeatToIdx[seat - 1] != 0 and notUsed.find(SeatToIdx[seat - 1]) != notUsed.end()) {
				if(SeatToIdx[seat - 2] != 0) {
					if(notUsed.find(SeatToIdx[seat - 2]) != notUsed.end()) {
						ok.insert(SeatToIdx[seat - 1]);
					}
				} else {
					ok.insert(SeatToIdx[seat - 1]);
				}
			}
			if(SeatToIdx[seat + 1] != 0 and notUsed.find(SeatToIdx[seat + 1]) != notUsed.end()) {
				if(SeatToIdx[seat + 2] != 0) {
					if(notUsed.find(SeatToIdx[seat + 2]) != notUsed.end()) {
						ok.insert(SeatToIdx[seat + 1]);
					}
				} else {
					ok.insert(SeatToIdx[seat + 1]);
				}
			}
		}
		// cout << "OK" << '\n';
		// for(int i : ok) {
		// 	cout << i << " ";
		// }
		// cout << '\n' << "Not Used" << '\n';
		// for(int i : notUsed) {
		// 	cout << i << " ";
		// }
		// cout << '\n';
		int idx, seat;
		if(ok.size()) {
			idx = *ok.begin();
			seat = IdxToSeat[idx];
		} else {
			idx = *notUsed.begin();
			seat = IdxToSeat[idx];
		}
		ok.erase(idx);
		notUsed.erase(idx);
		if(SeatToIdx[seat + 1] != 0) ok.erase(SeatToIdx[seat + 1]);
		if(SeatToIdx[seat - 1] != 0) ok.erase(SeatToIdx[seat - 1]);
		pq.emplace(a + b, idx);
		cout << seat << '\n';
		// cout << '\n';
	}
	return 0;
}
0