結果

問題 No.1508 Avoid being hit
ユーザー 👑 emthrmemthrm
提出日時 2021-05-14 23:26:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,101 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 203,252 KB
実行使用メモリ 13,972 KB
最終ジャッジ日時 2024-04-10 03:52:49
合計ジャッジ時間 14,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 371 ms
12,036 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 RE -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 394 ms
6,940 KB
testcase_17 AC 233 ms
6,944 KB
testcase_18 AC 169 ms
6,940 KB
testcase_19 AC 346 ms
6,940 KB
testcase_20 AC 459 ms
6,944 KB
testcase_21 AC 311 ms
6,940 KB
testcase_22 AC 382 ms
6,940 KB
testcase_23 AC 402 ms
6,940 KB
testcase_24 WA -
testcase_25 AC 422 ms
13,140 KB
testcase_26 AC 31 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 431 ms
13,284 KB
testcase_30 AC 227 ms
8,832 KB
testcase_31 AC 372 ms
11,920 KB
testcase_32 AC 407 ms
12,732 KB
testcase_33 WA -
testcase_34 AC 342 ms
10,944 KB
testcase_35 AC 35 ms
6,940 KB
testcase_36 AC 188 ms
7,680 KB
testcase_37 AC 84 ms
6,940 KB
testcase_38 AC 326 ms
9,600 KB
testcase_39 AC 169 ms
7,424 KB
testcase_40 AC 345 ms
11,348 KB
testcase_41 AC 198 ms
8,192 KB
testcase_42 AC 353 ms
11,224 KB
testcase_43 AC 434 ms
12,856 KB
testcase_44 AC 2 ms
6,944 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.reset(a[i]);
    reach.reset(b[i]);
    reach = (reach << 1) | reach | (reach >> 1);
    if (n < M) reach.reset(n);
  }
  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';
      reverse(ALL(k));
      REP(i, q) 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