結果

問題 No.1508 Avoid being hit
ユーザー 👑 Nachia
提出日時 2021-05-14 22:45:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,473 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 78,852 KB
最終ジャッジ日時 2025-01-21 11:48:10
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 2
other AC * 13 TLE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N,Q;
vector<int> A;
vector<int> B;
vector<int> L;
vector<int> R;

int main(){
  cin >> N >> Q;
  A.resize(Q); rep(i,Q){ cin >> A[i]; A[i]--; }
  B.resize(Q); rep(i,Q){ cin >> B[i]; B[i]--; }
  rep(i,Q) if(A[i] > B[i]) swap(A[i],B[i]);
  L.assign(Q+1,0);
  R.assign(Q+1,N-1);
  bool done = false;
  while(!done){
    done = true;
    for(int i=Q-1; i>=0; i--){
      L[i] = max(0,L[i+1]-1);
      if(L[i] == A[i]){ L[i]++; done=false; }
      if(L[i] == B[i]){ L[i]++; done=false; }
      R[i] = min(N-1,R[i+1]+1);
      if(R[i] == B[i]){ R[i]--; done=false; }
      if(R[i] == A[i]){ R[i]--; done=false; }
      if(L[i] > R[i]){ cout << "NO\n"; return 0; }
    }
    for(int i=1; i<=Q; i++){
      L[i] = max(0,L[i-1]-1);
      if(L[i] == A[i-1]){ L[i]++; done=false; }
      if(L[i] == B[i-1]){ L[i]++; done=false; }
      R[i] = min(N-1,R[i-1]+1);
      if(R[i] == B[i-1]){ R[i]--; done=false; }
      if(R[i] == A[i-1]){ R[i]--; done=false; }
      if(L[i] > R[i]){ cout << "NO\n"; return 0; }
    }
  }
  vector<int> ans;
  ans.push_back(L[0]+1);
  rep(i,Q) ans.push_back(L[i]+1);
  cout << "YES\n";
  for(int a : ans) cout << a << "\n";
  return 0;
}


struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;

0