結果
問題 | No.1508 Avoid being hit |
ユーザー |
![]() |
提出日時 | 2021-05-14 23:06:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 149 ms / 3,000 ms |
コード長 | 2,156 bytes |
コンパイル時間 | 2,115 ms |
コンパイル使用メモリ | 199,044 KB |
最終ジャッジ日時 | 2025-01-21 12:06:06 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/modint>using namespace atcoder;//#pragma GCC optimize("Ofast")using namespace std;#define reps(i,s,n) for(int i = s; i < n; i++)#define rep(i,n) reps(i,0,n)#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)#define Rrep(i,n) Rreps(i,n,0)#define ALL(a) a.begin(), a.end()using ll = long long;using vec = vector<ll>;using mat = vector<vec>;ll N,M,H,W,Q,K,A,B;string S;using P = pair<ll, ll>;using tp = tuple<ll, ll, ll>;const ll INF = (1LL<<61);template<class T> bool chmin(T &a, const T b){if(a > b) {a = b; return true;}else return false;}template<class T> bool chmax(T &a, const T b){if(a < b) {a = b; return true;}else return false;}template<class T> void my_printv(std::vector<T> v,bool endline = true){if(!v.empty()){for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";std::cout<<v.back();}if(endline) std::cout<<std::endl;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);cin>>N>>Q;vec a(Q), b(Q);rep(i, Q) {cin>>a[i];--a[i];}rep(i, Q) {cin>>b[i];--b[i];if(a[i] > b[i]) swap(a[i], b[i]);}vec left(Q, -1), right(Q, N);Rrep(i, Q){if(i != Q - 1) {chmax(left[i], left[i + 1] - 1);chmin(right[i], right[i + 1] + 1);}if(a[i] == left[i] + 1 || b[i] == left[i] + 1){left[i] += 1 + (a[i] == left[i] + 1 && b[i] == left[i] + 2);}if(a[i] == right[i] - 1 || b[i] == right[i] - 1){right[i] -= 1 + (a[i] == right[i] - 2 && b[i] == right[i] - 1);}if(left[i] >= right[i]){cout<<"NO"<<endl;exit(0);}}cout<<"YES"<<endl;int pos = max(0LL, left[0]);cout<<pos + 1<<endl;rep(i, Q){rep(j, 3){int nxtpos = pos - 1 + j;if(nxtpos < 0 || nxtpos >= N || nxtpos <= left[i] || nxtpos >= right[i] || nxtpos == a[i] || nxtpos == b[i]) continue;pos = nxtpos;break;}cout<<pos + 1<<endl;}}