結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
東前頭十一枚目
|
| 提出日時 | 2019-12-19 14:31:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,532 bytes |
| コンパイル時間 | 1,794 ms |
| コンパイル使用メモリ | 191,888 KB |
| 実行使用メモリ | 20,352 KB |
| 最終ジャッジ日時 | 2024-07-07 01:09:55 |
| 合計ジャッジ時間 | 10,498 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 22 |
ソースコード
#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;
if(k1 < k2) {
for(int i = k1, num = 0; i >= 1; --i) {
SeatToIdx[i] = num;
IdxToSeat[num] = i;
num += 2;
}
for(int i = k2, num = 1; i <= n; ++i) {
SeatToIdx[i] = num;
IdxToSeat[num] = i;
num += 2;
}
} else {
for(int i = k1, num = 0; i <= n; ++i) {
SeatToIdx[i] = num;
IdxToSeat[num] = i;
num += 2;
}
for(int i = k2, num = 1; i >= 1; --i) {
SeatToIdx[i] = num;
IdxToSeat[num] = i;
num += 2;
}
}
set<int> ok;
set<int> notUsed;
for(int i = 0; i < n; ++i) ok.insert(i);
for(int i = 0; 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;
while(q--) {
int64_t a, b; cin >> a >> b;
bool used = false;
while(pq.size()) {
int64_t t, idx;
tie(t, idx) = pq.top();
if(t > a) {
if(ok.empty()) {
if(notUsed.empty()) {
a = t;
continue;
}
}
break;
}
pq.pop();
int seat = IdxToSeat[idx];
bool left = true, right = true;
if(seat - 1 >= 1 and notUsed.find(SeatToIdx[seat - 1]) == notUsed.end()) {
left = false;
}
if(seat + 1 <= n and notUsed.find(SeatToIdx[seat + 1]) == notUsed.end()) {
right = false;
}
if(left and right) {
ok.insert(idx);
}
notUsed.insert(idx);
if(notUsed.find(SeatToIdx[seat - 1]) != notUsed.end()) {
if(seat - 2 >= 1 and notUsed.find(SeatToIdx[seat - 2]) != notUsed.end()) {
ok.insert(SeatToIdx[seat - 1]);
} else if(seat - 2 == 0) {
ok.insert(SeatToIdx[seat - 1]);
}
}
if(notUsed.find(SeatToIdx[seat + 1]) != notUsed.end()) {
if(seat + 2 <= n and notUsed.find(SeatToIdx[seat + 2]) != notUsed.end()) {
ok.insert(SeatToIdx[seat + 1]);
} else if(seat + 2 == n) {
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(seat + 1 <= n) ok.erase(SeatToIdx[seat + 1]);
if(seat - 1 >= 1) ok.erase(SeatToIdx[seat - 1]);
pq.emplace(a + b, idx);
cout << seat << '\n';
// cout << '\n';
}
return 0;
}
東前頭十一枚目