結果

問題 No.1508 Avoid being hit
ユーザー 👑 NachiaNachia
提出日時 2021-05-14 22:47:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 3,000 ms
コード長 1,434 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-10 05:33:18
合計ジャッジ時間 3,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 16 ms
5,376 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 9 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 21 ms
5,376 KB
testcase_21 AC 14 ms
5,376 KB
testcase_22 AC 17 ms
5,376 KB
testcase_23 AC 18 ms
5,376 KB
testcase_24 AC 24 ms
5,504 KB
testcase_25 AC 22 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 12 ms
5,376 KB
testcase_28 AC 12 ms
5,376 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 13 ms
5,376 KB
testcase_31 AC 20 ms
5,376 KB
testcase_32 AC 21 ms
5,376 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 22 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 13 ms
5,376 KB
testcase_37 AC 6 ms
5,376 KB
testcase_38 AC 18 ms
5,376 KB
testcase_39 AC 12 ms
5,376 KB
testcase_40 AC 23 ms
5,376 KB
testcase_41 AC 14 ms
5,376 KB
testcase_42 AC 23 ms
5,376 KB
testcase_43 AC 27 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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(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;

0