結果

問題 No.1508 Avoid being hit
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-05-14 23:25:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,162 ms / 3,000 ms
コード長 2,793 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 110,612 KB
実行使用メモリ 12,168 KB
最終ジャッジ日時 2024-04-10 03:50:25
合計ジャッジ時間 21,935 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 943 ms
11,196 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 463 ms
7,488 KB
testcase_17 AC 273 ms
6,944 KB
testcase_18 AC 200 ms
6,940 KB
testcase_19 AC 402 ms
6,944 KB
testcase_20 AC 536 ms
8,076 KB
testcase_21 AC 363 ms
6,944 KB
testcase_22 AC 454 ms
7,424 KB
testcase_23 AC 485 ms
7,628 KB
testcase_24 AC 1,162 ms
12,168 KB
testcase_25 AC 1,064 ms
11,876 KB
testcase_26 AC 78 ms
7,716 KB
testcase_27 AC 539 ms
9,504 KB
testcase_28 AC 544 ms
9,436 KB
testcase_29 AC 1,088 ms
11,860 KB
testcase_30 AC 584 ms
9,548 KB
testcase_31 AC 943 ms
11,308 KB
testcase_32 AC 1,027 ms
11,548 KB
testcase_33 AC 280 ms
8,320 KB
testcase_34 AC 833 ms
10,720 KB
testcase_35 AC 88 ms
7,724 KB
testcase_36 AC 477 ms
9,112 KB
testcase_37 AC 211 ms
8,092 KB
testcase_38 AC 672 ms
10,016 KB
testcase_39 AC 430 ms
9,032 KB
testcase_40 AC 875 ms
11,056 KB
testcase_41 AC 501 ms
9,268 KB
testcase_42 AC 882 ms
10,936 KB
testcase_43 AC 1,035 ms
11,580 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

using BS = bitset<100010>;

#ifdef LOCAL
constexpr int BLOCK = 2;
#else
constexpr int BLOCK = 300;
#endif

int N, Q;
vector<int> A, B;

int main() {
  for (; ~scanf("%d%d", &N, &Q); ) {
    A.resize(Q);
    B.resize(Q);
    for (int i = 0; i < Q; ++i) {
      scanf("%d", &A[i]);
    }
    for (int i = 0; i < Q; ++i) {
      scanf("%d", &B[i]);
    }
    
    vector<int> is;
    for (int i = 0; i < Q; i += BLOCK) {
      is.push_back(i);
    }
    const int len = is.size();
    is.push_back(Q);
    
    vector<BS> bss(len + 1);
    bss[0].reset();
    for (int x = 1; x <= N; ++x) {
      bss[0][x] = true;
    }
    for (int j = 0; j < len; ++j) {
      BS bs = bss[j];
      for (int i = is[j]; i < is[j + 1]; ++i) {
        bs = bs >> 1 | bs | bs << 1;
        bs[0] = false;
        bs[N + 1] = false;
        bs[A[i]] = false;
        bs[B[i]] = false;
      }
      bss[j + 1] = bs;
    }
    
    if (bss[len].any()) {
      vector<int> ans(Q + 1);
      ans[Q] = bss[len]._Find_first();
      for (int j = len; --j >= 0; ) {
        vector<BS> css(is[j + 1] - is[j] + 1);
        css[0] = bss[j];
        for (int i = is[j]; i < is[j + 1]; ++i) {
          const int pos = i - is[j];
          css[pos + 1] = css[pos] >> 1 | css[pos] | css[pos] << 1;
          css[pos + 1][0] = false;
          css[pos + 1][N + 1] = false;
          css[pos + 1][A[i]] = false;
          css[pos + 1][B[i]] = false;
        }
        for (int i = is[j + 1]; --i >= is[j]; ) {
          const int pos = i - is[j];
          for (int x = ans[i + 1] - 1; x <= ans[i + 1] + 1; ++x) {
            if (css[pos][x]) {
              ans[i] = x;
              break;
            }
          }
          assert(ans[i]);
        }
      }
      puts("YES");
      for (int i = 0; i <= Q; ++i) {
        printf("%d\n", ans[i]);
      }
    } else {
      puts("NO");
    }
  }
  return 0;
}
0