結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-16 23:30:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,515 bytes |
| コンパイル時間 | 1,224 ms |
| コンパイル使用メモリ | 95,588 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-07-02 20:53:44 |
| 合計ジャッジ時間 | 8,130 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 WA * 18 |
ソースコード
// 同時に複数人が離籍する場合を考慮していなかった
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int main(){
int n, k1, k2;
cin >> n >> k1 >> k2;
k1--, k2--;
double ent = k1 > k2 ? k1-0.2 : k1+0.2;
vector<bool> fil(n, 0);
priority_queue<pair<double,int>> ok1, ok2;
for(int i = 0; i < n; i++) ok1.push({-fabs(ent-i), i});
for(int i = 0; i < n; i++) ok2.push({-fabs(ent-i), i});
// time, enter -1, exit 0, id
priority_queue<pair<pair<int,int>, int>> event;
int q; cin >> q;
vector<int> a(q), b(q);
for(int i = 0; i < q; i++){
cin >> a[i] >> b[i];
event.push({{-a[i], -1}, i});
}
vector<int> ans(q);
queue<int> wait;
auto f = [&](int i)->bool{
for(int j = -1; j <= 1; j++){
if(inRange(i+j, 0, n)&&fil[i+j]) return false;
}
return true;
};
while(!event.empty()){
auto p = event.top(); event.pop();
int tim = -p.first.first, stat = p.first.second, ind = p.second;
if(ind < 0) ind = -ind;
if(stat == 0){
int pos = ans[ind];
fil[pos] = false;
if(!wait.empty()){
int now = wait.front(); wait.pop();
event.push({{-tim, -1}, -now});
}
for(int j = -1; j <= 1; j++){
if(inRange(pos+j,0,n)&&!fil[pos+j]){
if(f(pos+j)) ok1.push({-fabs(ent-(pos+j)), pos+j});
else ok2.push({-fabs(ent-(pos+j)), pos+j});
}
}
}else{
int sit = -1;
while(!ok1.empty()){
auto p = ok1.top(); ok1.pop();
if(!fil[p.second] && f(p.second)){
sit = p.second;
break;
}
}
if(sit == -1){
while(!ok2.empty()){
auto p = ok2.top(); ok2.pop();
if(!fil[p.second]){
sit = p.second;
break;
}
}
}
if(sit == -1){
wait.push(ind);
continue;
}
ans[ind] = sit;
fil[sit] = true;
event.push({{-(tim+b[ind]), 0}, ind});
}
}
for(int i = 0; i < q; i++) cout << ans[i]+1 << endl;
return 0;
}