結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
東前頭十一枚目
|
| 提出日時 | 2019-12-19 16:18:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 450 ms / 2,000 ms |
| コード長 | 2,762 bytes |
| コンパイル時間 | 2,276 ms |
| コンパイル使用メモリ | 201,432 KB |
| 実行使用メモリ | 20,992 KB |
| 最終ジャッジ日時 | 2024-07-07 01:32:59 |
| 合計ジャッジ時間 | 12,378 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#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;
}
東前頭十一枚目