結果

問題 No.1508 Avoid being hit
ユーザー 👑 NachiaNachia
提出日時 2021-05-14 22:45:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,473 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 18,232 KB
最終ジャッジ日時 2024-04-10 01:50:14
合計ジャッジ時間 9,996 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

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