結果

問題 No.1508 Avoid being hit
ユーザー 👑 emthrmemthrm
提出日時 2021-05-14 23:04:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,911 bytes
コンパイル時間 2,752 ms
コンパイル使用メモリ 198,828 KB
実行使用メモリ 14,040 KB
最終ジャッジ日時 2024-04-10 02:25:47
合計ジャッジ時間 8,279 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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() {
  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]);
  }
  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) f(f, i - 1, g - 1);
      f(f, i - 1, g);
      if (g + 1 < n) f(f, i - 1, g + 1);
    }
    k.pop_back();
  };
  if (a[q - 1] > 0) f(f, q - 2, a[q - 1] - 1);
  if (a[q - 1] + 1 < b[q - 1]) {
    f(f, q - 2, a[q - 1] + 1);
    f(f, q - 2, b[q - 1] - 1);
  }
  if (b[q - 1] + 1 < n) f(f, q - 2, b[q - 1] + 1);
  cout << "NO\n";
  return 0;
}
0