結果

問題 No.953 席
ユーザー face4face4
提出日時 2019-12-17 10:29:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,469 bytes
コンパイル時間 958 ms
コンパイル使用メモリ 94,692 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2023-09-15 19:22:49
合計ジャッジ時間 8,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 245 ms
7,140 KB
testcase_03 AC 242 ms
8,132 KB
testcase_04 AC 248 ms
7,100 KB
testcase_05 AC 240 ms
6,928 KB
testcase_06 WA -
testcase_07 AC 168 ms
12,372 KB
testcase_08 AC 253 ms
9,496 KB
testcase_09 AC 141 ms
13,312 KB
testcase_10 AC 56 ms
5,420 KB
testcase_11 AC 187 ms
8,492 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 AC 253 ms
7,664 KB
testcase_24 WA -
testcase_25 AC 267 ms
10,056 KB
testcase_26 AC 229 ms
6,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)
typedef long long ll;

int main(){
    int n, k1, k2;
    cin >> n >> k1 >> k2;
    double ent = k1 > k2 ? k1-0.2 : k1+0.2;
    vector<bool> fil(n+1, 0);
    priority_queue<pair<double,int>> ok1, ok2;
    for(int i = 1; i <= n; i++) ok1.push({-fabs(ent-i), i});
    for(int i = 1; i <= n; i++) ok2.push({-fabs(ent-i), i});
    // time, enter -1, exit 0, id
    priority_queue<pair<pair<ll,int>, int>> event;
    int q;  cin >> q;
    vector<int> a(q+1), b(q+1);
    for(int i = 1; i <= q; i++){
        cin >> a[i] >> b[i];
        event.push({{-a[i], -1}, i});
    }
    vector<int> ans(q+1);
    queue<int> wait;
    auto f = [&](int i)->bool{
        for(int j = -1; j <= 1; j++){
            if(inRange(i+j, 1, n)&&fil[i+j])    return false;
        }
        return true;
    };
    while(!event.empty()){
        auto p = event.top();   event.pop();
        ll tim = -p.first.first;
        int stat = p.first.second, ind = p.second;
        if(ind <= 0) ind += q;
        if(stat == 0){
            int pos = ans[ind];
            fil[pos] = false;
            if(!wait.empty()){
                int now = wait.front(); wait.pop();
                event.push({{-tim, -1}, now-q});
            }
            for(int j = -1; j <= 1; j++){
                if(inRange(pos+j,1,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 = 1; i <= q; i++)  cout << ans[i] << endl;
    return 0;
}
0