結果

問題 No.1508 Avoid being hit
ユーザー 👑 emthrmemthrm
提出日時 2021-05-14 23:42:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 535 ms / 3,000 ms
コード長 2,226 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 203,448 KB
実行使用メモリ 13,972 KB
最終ジャッジ日時 2024-04-10 05:37:05
合計ジャッジ時間 14,777 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 429 ms
11,912 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 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,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 452 ms
6,944 KB
testcase_17 AC 261 ms
6,940 KB
testcase_18 AC 192 ms
6,940 KB
testcase_19 AC 391 ms
6,944 KB
testcase_20 AC 535 ms
6,940 KB
testcase_21 AC 358 ms
6,940 KB
testcase_22 AC 444 ms
6,940 KB
testcase_23 AC 476 ms
6,944 KB
testcase_24 AC 527 ms
13,972 KB
testcase_25 AC 497 ms
13,012 KB
testcase_26 AC 36 ms
6,944 KB
testcase_27 AC 246 ms
8,320 KB
testcase_28 AC 248 ms
8,576 KB
testcase_29 AC 496 ms
13,416 KB
testcase_30 AC 266 ms
8,704 KB
testcase_31 AC 430 ms
12,168 KB
testcase_32 AC 462 ms
12,860 KB
testcase_33 AC 127 ms
6,944 KB
testcase_34 AC 387 ms
10,940 KB
testcase_35 AC 41 ms
6,940 KB
testcase_36 AC 221 ms
7,936 KB
testcase_37 AC 100 ms
6,940 KB
testcase_38 AC 318 ms
9,600 KB
testcase_39 AC 199 ms
7,552 KB
testcase_40 AC 405 ms
11,348 KB
testcase_41 AC 239 ms
8,064 KB
testcase_42 AC 407 ms
11,356 KB
testcase_43 AC 482 ms
12,728 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,944 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] == b[i] || 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] == b[i] || 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