結果
問題 | No.1508 Avoid being hit |
ユーザー |
|
提出日時 | 2021-05-14 22:39:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 818 bytes |
コンパイル時間 | 602 ms |
コンパイル使用メモリ | 67,800 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-10-02 02:39:00 |
合計ジャッジ時間 | 7,296 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 12 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | 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]; 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],r=R[i+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-1; R[i]=r+1; if(L[i]<0)L[i]=0; if(R[i]>N+1)R[i]=N+1; } cout<<"YES"<<endl; int pos=L[0]+1; cout<<pos<<endl; for(int i=0;i<Q;i++) { if(pos<=L[i])pos++; else if(pos>=R[i])pos--; else if(pos==A[i]||pos==B[i]) { pos--; if(pos<=L[i]||pos==A[i]||pos==B[i])pos+=2; } cout<<pos<<endl; } }