結果
問題 | No.1508 Avoid being hit |
ユーザー |
|
提出日時 | 2021-05-14 22:56:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 162 ms / 3,000 ms |
コード長 | 851 bytes |
コンパイル時間 | 750 ms |
コンパイル使用メモリ | 67,584 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 07:08:34 |
合計ジャッジ時間 | 5,587 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> using namespace std; int N,Q; int A[1<<17],B[1<<17]; int L[1<<17],R[1<<17]; int L2[1<<17],R2[1<<17]; main() { cin>>N>>Q; for(int i=0;i<Q;i++)cin>>A[i]; for(int i=0;i<Q;i++)cin>>B[i]; L[Q]=0,R[Q]=N+1; for(int i=Q;i--;) { if(A[i]>B[i])swap(A[i],B[i]); int l=L[i+1]-1,r=R[i+1]+1; if(l<0)l=0; if(r>N+1)r=N+1; if(A[i]==l+1||B[i]==l+1) { l++; if(A[i]==l&&B[i]==l+1)l++; } if(A[i]==r-1||B[i]==r-1) { r--; if(A[i]==r-1&&B[i]==r)r--; } if(l+1>=r) { cout<<"NO"<<endl; return 0; } L[i]=l; R[i]=r; } cout<<"YES"<<endl; int pos=L[0]+1; cout<<pos<<endl; for(int i=0;i<Q;i++) { int nxt=-1; for(int v:{pos-1,pos,pos+1}) { if(v<=L[i])continue; if(v>=R[i])continue; if(v==A[i]||v==B[i])continue; nxt=v; break; } pos=nxt; cout<<pos<<endl; } }