結果

問題 No.953 席
ユーザー face4face4
提出日時 2019-12-16 23:21:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,482 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 94,228 KB
実行使用メモリ 11,784 KB
最終ジャッジ日時 2023-09-15 18:54:20
合計ジャッジ時間 8,903 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 167 ms
11,096 KB
testcase_08 AC 253 ms
8,508 KB
testcase_09 AC 143 ms
11,784 KB
testcase_10 AC 55 ms
5,360 KB
testcase_11 AC 184 ms
7,100 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 265 ms
7,800 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 同時に複数人が離籍する場合を考慮していなかった
#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(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;
}
0