結果
| 問題 | 
                            No.1508 Avoid being hit
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Nachia
                         | 
                    
| 提出日時 | 2021-05-14 22:47:27 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 27 ms / 3,000 ms | 
| コード長 | 1,434 bytes | 
| コンパイル時間 | 1,042 ms | 
| コンパイル使用メモリ | 79,316 KB | 
| 最終ジャッジ日時 | 2025-01-21 11:49:39 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
#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(L[i],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(R[i],R[i+1]+1);
      if(R[i] == B[i]){ R[i]--; done=false; }
      if(R[i] == A[i]){ R[i]--; done=false; }
    }
    for(int i=0; i<Q; i++){
      if(L[i] == A[i]){ L[i]++; done=false; }
      if(L[i] == B[i]){ L[i]++; done=false; }
      L[i+1] = max(L[i+1],L[i]-1);
      if(R[i] == B[i]){ R[i]--; done=false; }
      if(R[i] == A[i]){ R[i]--; done=false; }
      R[i+1] = min(R[i+1],R[i]+1);
    }
    rep(i,Q+1) 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;
            
            
            
        
            
Nachia