結果
問題 | No.1508 Avoid being hit |
ユーザー |
![]() |
提出日時 | 2021-05-14 22:57:06 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 172 ms / 3,000 ms |
コード長 | 2,936 bytes |
コンパイル時間 | 2,110 ms |
使用メモリ | 19,800 KB |
最終ジャッジ日時 | 2022-11-26 01:01:43 |
合計ジャッジ時間 | 7,132 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 172 ms
14,664 KB |
testcase_01 | AC | 1 ms
3,372 KB |
testcase_02 | AC | 1 ms
3,376 KB |
testcase_03 | AC | 2 ms
3,376 KB |
testcase_04 | AC | 1 ms
3,372 KB |
testcase_05 | AC | 2 ms
3,480 KB |
testcase_06 | AC | 1 ms
3,532 KB |
testcase_07 | AC | 1 ms
3,448 KB |
testcase_08 | AC | 1 ms
3,516 KB |
testcase_09 | AC | 1 ms
3,376 KB |
testcase_10 | AC | 1 ms
3,436 KB |
testcase_11 | AC | 1 ms
3,376 KB |
testcase_12 | AC | 2 ms
3,372 KB |
testcase_13 | AC | 1 ms
3,376 KB |
testcase_14 | AC | 1 ms
3,436 KB |
testcase_15 | AC | 1 ms
3,472 KB |
testcase_16 | AC | 63 ms
13,592 KB |
testcase_17 | AC | 36 ms
9,108 KB |
testcase_18 | AC | 33 ms
7,596 KB |
testcase_19 | AC | 54 ms
12,032 KB |
testcase_20 | AC | 81 ms
15,188 KB |
testcase_21 | AC | 54 ms
11,268 KB |
testcase_22 | AC | 66 ms
13,396 KB |
testcase_23 | AC | 76 ms
13,932 KB |
testcase_24 | AC | 158 ms
19,800 KB |
testcase_25 | AC | 144 ms
18,364 KB |
testcase_26 | AC | 11 ms
4,236 KB |
testcase_27 | AC | 80 ms
10,776 KB |
testcase_28 | AC | 72 ms
10,696 KB |
testcase_29 | AC | 155 ms
18,676 KB |
testcase_30 | AC | 80 ms
11,552 KB |
testcase_31 | AC | 124 ms
16,496 KB |
testcase_32 | AC | 134 ms
17,880 KB |
testcase_33 | AC | 38 ms
6,992 KB |
testcase_34 | AC | 121 ms
16,004 KB |
testcase_35 | AC | 14 ms
4,452 KB |
testcase_36 | AC | 71 ms
10,484 KB |
testcase_37 | AC | 31 ms
6,196 KB |
testcase_38 | AC | 100 ms
13,696 KB |
testcase_39 | AC | 64 ms
9,636 KB |
testcase_40 | AC | 126 ms
16,504 KB |
testcase_41 | AC | 72 ms
10,752 KB |
testcase_42 | AC | 131 ms
16,812 KB |
testcase_43 | AC | 155 ms
19,140 KB |
testcase_44 | AC | 1 ms
3,376 KB |
testcase_45 | AC | 1 ms
3,404 KB |
ソースコード
#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; } } }