結果

問題 No.1508 Avoid being hit
ユーザー 👑 emthrmemthrm
提出日時 2021-05-14 23:28:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,194 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 202,680 KB
実行使用メモリ 13,844 KB
最終ジャッジ日時 2024-04-10 03:57:31
合計ジャッジ時間 15,510 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 442 ms
11,904 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 RE -
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 RE -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 469 ms
6,940 KB
testcase_17 AC 271 ms
6,944 KB
testcase_18 AC 199 ms
6,940 KB
testcase_19 AC 398 ms
6,940 KB
testcase_20 AC 533 ms
6,940 KB
testcase_21 AC 359 ms
6,944 KB
testcase_22 AC 451 ms
6,940 KB
testcase_23 AC 483 ms
6,940 KB
testcase_24 AC 542 ms
13,844 KB
testcase_25 AC 500 ms
13,016 KB
testcase_26 AC 37 ms
6,940 KB
testcase_27 AC 254 ms
8,448 KB
testcase_28 AC 253 ms
8,448 KB
testcase_29 AC 507 ms
13,412 KB
testcase_30 AC 271 ms
8,832 KB
testcase_31 AC 447 ms
12,040 KB
testcase_32 AC 482 ms
12,604 KB
testcase_33 AC 132 ms
6,944 KB
testcase_34 AC 401 ms
10,856 KB
testcase_35 AC 42 ms
6,944 KB
testcase_36 AC 225 ms
7,936 KB
testcase_37 AC 100 ms
6,940 KB
testcase_38 AC 321 ms
9,600 KB
testcase_39 AC 206 ms
7,552 KB
testcase_40 AC 418 ms
11,476 KB
testcase_41 AC 240 ms
8,064 KB
testcase_42 AC 421 ms
11,356 KB
testcase_43 AC 495 ms
12,732 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int M = 100000;
  int n, q; cin >> n >> q;
  vector<int> a(q), b(q);
  REP(i, q) cin >> a[i], --a[i];
  REP(i, q) cin >> b[i], --b[i];
  REP(i, q) {
    if (a[i] > b[i]) swap(a[i], b[i]);
  }
  bitset<M> reach(0);
  REP(i, n) reach.set(i);
  REP(i, q) {
    reach = (reach << 1) | reach | (reach >> 1);
    if (n < M) reach.reset(n);
    reach.reset(a[i]);
    reach.reset(b[i]);
  }
  if (reach.none()) {
    cout << "NO\n";
    return 0;
  }
  vector<int> k;
  auto f = [&](auto &&f, int i, int g) -> void {
    k.emplace_back(g);
    if (i == -1) {
      cout << "YES\n" << g + 1 << '\n';
      assert(k.size() == q);
      reverse(ALL(k));
      REP(i, q) {
        assert(k[i] != a[i] && k[i] != b[i]);
        cout << k[i] + 1 << '\n';
      }
      exit(0);
    }
    if (a[i] == g) {
      if (g > 0) f(f, i - 1, g - 1);
      if (a[i] + 1 < b[i]) f(f, i - 1, g + 1);
    } else if (b[i] == g) {
      if (g + 1 < n) f(f, i - 1, g + 1);
      if (a[i] + 1 < b[i]) f(f, i - 1, g - 1);
    } else {
      if (g > 0 && a[i] != g - 1 && b[i] != g - 1) f(f, i - 1, g - 1);
      f(f, i - 1, g);
      if (g + 1 < n && a[i] != g + 1 && b[i] != g + 1) f(f, i - 1, g + 1);
    }
    k.pop_back();
  };
  REP(i, n) {
    if (reach[i]) f(f, q - 2, i);
  }
  assert(false);
}
0