結果

問題 No.1508 Avoid being hit
ユーザー SSRSSSRS
提出日時 2021-05-14 23:48:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,884 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 175,620 KB
実行使用メモリ 14,696 KB
最終ジャッジ日時 2024-04-10 04:38:12
合計ジャッジ時間 12,604 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 2 ms
6,944 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
6,940 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
6,944 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 64 ms
13,584 KB
testcase_17 AC 37 ms
9,216 KB
testcase_18 AC 30 ms
7,552 KB
testcase_19 AC 54 ms
12,016 KB
testcase_20 AC 79 ms
14,696 KB
testcase_21 AC 54 ms
11,136 KB
testcase_22 AC 65 ms
12,980 KB
testcase_23 AC 73 ms
13,812 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> A(Q);
  for (int i = 0; i < Q; i++){
    cin >> A[i];
    A[i]--;
  }
  vector<int> B(Q);
  for (int i = 0; i < Q; i++){
    cin >> B[i];
    B[i]--;
  }
  for (int i = 0; i < Q; i++){
    if (A[i] > B[i]){
      swap(A[i], B[i]);
    }
  }
  vector<vector<int>> E(Q * 2 + 2);
  for (int i = 0; i < Q; i++){
    if (A[i] == 0){
      E[Q * 2].push_back(i * 2);
    }
    if (B[i] == 0){
      E[Q * 2].push_back(i * 2 + 1);
    }
    if (A[i] == N - 1){
      E[i * 2].push_back(Q * 2 + 1);
    }
    if (B[i] == N - 1){
      E[i * 2 + 1].push_back(Q * 2 + 1);
    }
    if (abs(A[i] - B[i]) == 1){
      E[i * 2].push_back(i * 2 + 1);
      E[i * 2 + 1].push_back(i * 2);
    }
    if (i > 0){
      if (A[i] == A[i - 1]){
        E[i * 2 - 2].push_back(i * 2);
        E[i * 2].push_back(i * 2 - 2);
      }
      if (A[i] == B[i - 1]){
        E[i * 2 - 1].push_back(i * 2);
        E[i * 2].push_back(i * 2 - 1);
      }
      if (B[i] == A[i - 1]){
        E[i * 2 - 2].push_back(i * 2 + 1);
        E[i * 2 + 1].push_back(i * 2 - 2);
      }
      if (B[i] == B[i - 1]){
        E[i * 2 - 1].push_back(i * 2 + 1);
        E[i * 2 + 1].push_back(i * 2 - 1);
      }
    }
  }
  vector<bool> used(Q * 2 + 2, false);
  used[Q * 2] = true;
  queue<int> q;
  q.push(Q * 2);
  while (!q.empty()){
    int v = q.front();
    q.pop();
    for (int w : E[v]){
      if (!used[w]){
        used[w] = true;
        q.push(w);
      }
    }
  }
  if (used[Q * 2 + 1]){
    cout << "NO" << endl;
  } else {
    assert(false);
    vector<bool> ok1(Q, true), ok2(Q, true);
    for (int i = Q - 1; i >= 0; i--){
      if (A[i] == 0){
        ok1[i] = false;
      }
      if (B[i] == N - 1){
        ok2[i] = false;
      }
      if (i < Q - 1){
      }
    }
    cout << "YES" << endl;
  }
}
0