結果
問題 | No.1508 Avoid being hit |
ユーザー |
![]() |
提出日時 | 2021-05-14 23:52:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,565 bytes |
コンパイル時間 | 1,690 ms |
コンパイル使用メモリ | 171,796 KB |
実行使用メモリ | 7,116 KB |
最終ジャッジ日時 | 2024-10-02 06:21:14 |
合計ジャッジ時間 | 7,037 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 WA * 11 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=998244353; constexpr ll INF=2e18; int main(){ int n, q; cin >> n >> q; VI a(q), b(q); REP(i,q) cin >> a[i], a[i]--; REP(i,q) cin >> b[i], b[i]--; int l=-1, r=n; VI x(q), y(q); for(int i=q-1;i>=0;i--){ if(a[i]>b[i]) swap(a[i],b[i]); if(l+1==a[i]&&a[i]+1==b[i]) l++; else if(l==a[i]&&a[i]+1==b[i]) l+=0; else l=max(l-1,-1); if(r-1==b[i]&&a[i]+1==b[i]) r--; else if(r==b[i]&&a[i]+1==b[i]) r+=0; else r=min(r+1,n); x[i]=l; y[i]=r; } VI ans; int now=x[0]+1; ans.push_back(now); bool no=0; REP(i,q){ int p=-1; for(int j=-1;j<=1;j++){ bool ok=1; if((i<q-1&&(now+j>=y[i+1]||now+j<=x[i+1]))||now+j>=n||now+j<0) ok=0; if(now+j==a[i]) ok=0; if(now+j==b[i]) ok=0; if(ok){ p=now+j; break; } } now=p; if(now==-1){ no=1; break; } ans.push_back(now); } if(no){ cout << "NO" << endl; } else{ cout << "YES" << endl; REP(i,q+1){ cout << ans[i]+1 << endl; } } }