結果

問題 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,214 ms / 3,000 ms
コード長 2,793 bytes
コンパイル時間 1,148 ms
コンパイル使用メモリ 106,168 KB
実行使用メモリ 12,004 KB
最終ジャッジ日時 2023-07-25 10:50:29
合計ジャッジ時間 23,559 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 999 ms
11,068 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 436 ms
7,128 KB
testcase_17 AC 257 ms
5,344 KB
testcase_18 AC 188 ms
5,008 KB
testcase_19 AC 377 ms
6,656 KB
testcase_20 AC 509 ms
7,652 KB
testcase_21 AC 342 ms
6,420 KB
testcase_22 AC 427 ms
7,264 KB
testcase_23 AC 455 ms
7,564 KB
testcase_24 AC 1,209 ms
12,004 KB
testcase_25 AC 1,104 ms
11,500 KB
testcase_26 AC 83 ms
7,376 KB
testcase_27 AC 566 ms
9,304 KB
testcase_28 AC 565 ms
9,212 KB
testcase_29 AC 1,214 ms
11,724 KB
testcase_30 AC 604 ms
9,424 KB
testcase_31 AC 979 ms
11,112 KB
testcase_32 AC 1,060 ms
11,288 KB
testcase_33 AC 292 ms
8,092 KB
testcase_34 AC 864 ms
10,480 KB
testcase_35 AC 92 ms
7,336 KB
testcase_36 AC 491 ms
8,988 KB
testcase_37 AC 220 ms
8,036 KB
testcase_38 AC 699 ms
9,776 KB
testcase_39 AC 450 ms
8,716 KB
testcase_40 AC 907 ms
10,684 KB
testcase_41 AC 523 ms
9,148 KB
testcase_42 AC 920 ms
10,772 KB
testcase_43 AC 1,067 ms
11,472 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 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