結果

問題 No.1508 Avoid being hit
ユーザー shiomusubi496shiomusubi496
提出日時 2021-05-14 22:57:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 3,000 ms
コード長 2,936 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 209,944 KB
実行使用メモリ 20,088 KB
最終ジャッジ日時 2024-04-10 05:34:05
合計ジャッジ時間 7,550 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
14,856 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 69 ms
13,824 KB
testcase_17 AC 39 ms
9,472 KB
testcase_18 AC 35 ms
7,680 KB
testcase_19 AC 56 ms
12,244 KB
testcase_20 AC 91 ms
15,468 KB
testcase_21 AC 60 ms
11,392 KB
testcase_22 AC 76 ms
13,516 KB
testcase_23 AC 83 ms
14,188 KB
testcase_24 AC 193 ms
20,088 KB
testcase_25 AC 173 ms
18,512 KB
testcase_26 AC 14 ms
6,940 KB
testcase_27 AC 91 ms
10,880 KB
testcase_28 AC 89 ms
11,136 KB
testcase_29 AC 172 ms
18,868 KB
testcase_30 AC 94 ms
11,520 KB
testcase_31 AC 154 ms
16,812 KB
testcase_32 AC 161 ms
17,920 KB
testcase_33 AC 44 ms
7,168 KB
testcase_34 AC 143 ms
16,384 KB
testcase_35 AC 17 ms
6,940 KB
testcase_36 AC 79 ms
10,496 KB
testcase_37 AC 37 ms
6,940 KB
testcase_38 AC 113 ms
13,824 KB
testcase_39 AC 77 ms
9,856 KB
testcase_40 AC 155 ms
16,880 KB
testcase_41 AC 87 ms
11,008 KB
testcase_42 AC 155 ms
16,896 KB
testcase_43 AC 176 ms
19,560 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int N,Q; cin>>N>>Q;
    vector<int>A(Q),B(Q);
    for(int i=0;i<Q;i++) cin>>A[i],A[i]--;
    for(int i=0;i<Q;i++) cin>>B[i],B[i]--;
    vector<set<pair<int,int>>>dp(Q+1);
    for(int i=Q;i--;){
        set<pair<int,int>>&st=dp[i+1];
        auto it=st.upper_bound({A[i],N+2});
        if(it==st.begin() || prev(it)->second<=A[i]){
            auto itr=st.insert({A[i],A[i]+1}).first;
            if(itr!=st.begin() && prev(itr)->second==itr->first){
                itr=st.insert({prev(itr)->first,itr->second}).first;
                st.erase(prev(itr));
                st.erase(next(itr));
            }
            if(next(itr)!=st.end() && itr->second==next(itr)->first){
                itr=st.insert({itr->first,next(itr)->second}).first;
                st.erase(prev(itr));
                st.erase(next(itr));
            }
        }
        it=st.upper_bound({B[i],N+2});
        if(it==st.begin() || prev(it)->second<=B[i]){
            auto itr=st.insert({B[i],B[i]+1}).first;
            if(itr!=st.begin() && prev(itr)->second==itr->first){
                itr=st.insert({prev(itr)->first,itr->second}).first;
                st.erase(prev(itr));
                st.erase(next(itr));
            }
            if(next(itr)!=st.end() && itr->second==next(itr)->first){
                itr=st.insert({itr->first,next(itr)->second}).first;
                st.erase(prev(itr));
                st.erase(next(itr));
            }
        }
        if(st.size()){
            if(st.begin()->first==0) st.erase(next(st.insert({-1,st.begin()->second}).first));
            if(prev(st.end())->second==N) st.erase(prev(st.insert({prev(st.end())->first,N+1}).first));
            for(auto[a,b]:st){
                if(a+1<b-1)dp[i].insert({a+1,b-1});
            }
            if(st.begin()->first==-1) st.erase(prev(st.insert({0,st.begin()->second}).first));
            if(prev(st.end())->second==N+1) st.erase(next(st.insert({prev(st.end())->first,N}).first));
        }
    }
    if(dp[0].count({0,N})) puts("NO");
    else{
        puts("YES");
        int now=0;
        for(int i=0;i<N;i++){
            auto it=dp[0].upper_bound({i,N+2});
            if(it==dp[0].begin() || prev(it)->second<=i){
                now=i;
                break;
            }
        }
        cout<<now+1<<endl;
        for(int i=0;i<Q;i++){
            set<pair<int,int>> st=dp[i+1];
            set<pair<int,int>>::iterator it;
            if((it=st.upper_bound({now,N+2}))==st.begin() || prev(it)->second<=now){
                now=now;
            }else if(now!=0 && (it=st.upper_bound({now-1,N+2}))==st.begin() || prev(it)->second<=now-1){
                now=now-1;
            }else if((it=st.upper_bound({now+1,N+2}))==st.begin() || prev(it)->second<=now+1){
                now=now+1;
            }
            cout<<now+1<<endl;
        }
    }
}
0