結果

問題 No.953 席
ユーザー ngtkanangtkana
提出日時 2020-04-12 00:10:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,190 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 224,228 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2023-10-19 21:51:19
合計ジャッジ時間 7,249 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 187 ms
10,784 KB
testcase_08 AC 179 ms
11,252 KB
testcase_09 AC 162 ms
11,048 KB
testcase_10 AC 51 ms
5,912 KB
testcase_11 AC 133 ms
10,864 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 170 ms
11,252 KB
testcase_26 AC 50 ms
10,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k0,k1,q;std::cin>>n>>k0>>k1>>q;k0--,k1--;
    std::vector<std::tuple<lint,lint,lint>>events;
    for(lint i=0;i<q;i++){
        lint a,b;std::cin>>a>>b;
        events.emplace_back(a+b,0,i);
        events.emplace_back(a,1,i);
    }
    auto dist_to_exit=[&](lint x){return std::abs(3*x-(2*k0+k1));};
    auto nearer=[&](lint x,lint y){return dist_to_exit(x)<dist_to_exit(y);};
    using nearer_t=std::decay_t<decltype(nearer)>;
    std::sort(ALL(events));
    std::deque<lint>wait;
    std::vector<lint>ans(q),ckd(n,-1);
    std::array<std::set<lint,nearer_t>,2>sets{std::set<lint,nearer_t>(nearer),std::set<lint,nearer_t>(nearer)};
    for(lint i=0;i<n;i++)sets.at(0).insert(i);
    auto update=[&](lint i){
        for(auto&&set:sets)if(auto f=set.find(i);f!=set.end())set.erase(f);
        if(ckd.at(i)!=-1)return;
        sets.at((i==0||ckd.at(i-1)==-1)&&(i==n-1||ckd.at(i+1)==-1)?0:1).insert(i);
    };
    auto update_three=[&](lint i){
        if(i)update(i-1);
        update(i);
        if(i!=n-1)update(i+1);
    };
    for(lint l=0,r=0;l<2*q;l=r){
        for(r=l;r<2*q&&std::get<0>(events.at(l))==std::get<0>(events.at(r));r++);
        for(;l<r&&std::get<1>(events.at(l))==0;l++){
            lint i=std::get<2>(events.at(l));
            ckd.at(ans.at(i))=-1;
            update_three(ans.at(i));
        }
        for(;l<r;l++){
            lint i=std::get<2>(events.at(l));
            wait.push_back(i);
        }
        while(!wait.empty()){
            bool found=false;
            for(auto&&set:sets){
                if(set.empty())continue;
                lint i=wait.front();wait.pop_front();
                lint a=*set.begin();
                set.erase(set.begin());
                ans.at(i)=a;
                ckd.at(a)=i;
                update_three(ans.at(i));
                found=true;
                break;
            }
            if(!found)break;
        }
    }
    for(lint x:ans){
        std::cout<<x+1<<'\n';
    }
}
/*
 * ans[ 人 ] = 座った席です。
 * ckd[ 席 ] = 人が座っていれば true です。
 * set[ 0 ] = 両隣の空いている席の集合です。(入り口に近い順です。)
 * set[ 1 ] = 隣に人が座っているけれども空いている席の集合です。
 * wait = 待っている人の集合を、キューで管理です。
 *
 * * 退店
 * まず、その人の席を特定です。
 * ckd を更新し、両隣含めた 3 席の set を更新です。
 * 待っている方がいらしても、まだお待ちいただきましょう。
 *
 * * 来店
 * 空いていても問答無用で列に並んでいただきましょう。
 *
 * * 待ちの解消
 * 待っている方がいらして、また席があいていれば埋めるをします。
 * 具体的には、まず wait から人を pop します。
 * 空いている席を探します。
 * ckd を更新し、両隣含めた 3 席の set を更新です。
 *
 */
0