結果

問題 No.1508 Avoid being hit
ユーザー tnakao0123tnakao0123
提出日時 2021-05-16 19:42:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 3,000 ms
コード長 2,221 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 99,620 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-15 10:42:53
合計ジャッジ時間 5,174 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
9,472 KB
testcase_01 AC 3 ms
5,888 KB
testcase_02 AC 3 ms
5,888 KB
testcase_03 AC 4 ms
6,016 KB
testcase_04 AC 4 ms
6,144 KB
testcase_05 AC 4 ms
6,144 KB
testcase_06 AC 4 ms
6,016 KB
testcase_07 AC 3 ms
6,272 KB
testcase_08 AC 4 ms
6,016 KB
testcase_09 AC 3 ms
6,144 KB
testcase_10 AC 4 ms
5,888 KB
testcase_11 AC 3 ms
6,144 KB
testcase_12 AC 4 ms
6,144 KB
testcase_13 AC 4 ms
5,888 KB
testcase_14 AC 4 ms
6,016 KB
testcase_15 AC 4 ms
6,016 KB
testcase_16 AC 27 ms
8,192 KB
testcase_17 AC 16 ms
7,204 KB
testcase_18 AC 16 ms
7,424 KB
testcase_19 AC 24 ms
7,680 KB
testcase_20 AC 35 ms
9,472 KB
testcase_21 AC 24 ms
8,320 KB
testcase_22 AC 30 ms
8,704 KB
testcase_23 AC 33 ms
9,088 KB
testcase_24 AC 52 ms
10,880 KB
testcase_25 AC 46 ms
10,584 KB
testcase_26 AC 6 ms
6,528 KB
testcase_27 AC 25 ms
8,168 KB
testcase_28 AC 26 ms
8,380 KB
testcase_29 AC 48 ms
10,624 KB
testcase_30 AC 27 ms
8,544 KB
testcase_31 AC 43 ms
9,856 KB
testcase_32 AC 46 ms
10,496 KB
testcase_33 AC 15 ms
7,276 KB
testcase_34 AC 42 ms
10,080 KB
testcase_35 AC 8 ms
6,656 KB
testcase_36 AC 25 ms
8,448 KB
testcase_37 AC 14 ms
7,168 KB
testcase_38 AC 36 ms
9,344 KB
testcase_39 AC 24 ms
8,320 KB
testcase_40 AC 45 ms
10,368 KB
testcase_41 AC 27 ms
8,448 KB
testcase_42 AC 45 ms
10,240 KB
testcase_43 AC 52 ms
11,136 KB
testcase_44 AC 4 ms
6,016 KB
testcase_45 AC 3 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1508.cc:  No.1508 Avoid being hit - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_Q = 100000;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int as[MAX_Q], bs[MAX_Q], vs[MAX_Q + 1];
vpii gs[MAX_Q + 1];

/* subroutines */

void splitg(int x, vpii &g) {
  vpii tg;
  for (auto p: g) {
    if (p.first <= x && x < p.second) {
      if (p.first < x) tg.push_back(pii(p.first, x));
      if (x + 1 < p.second) tg.push_back(pii(x + 1, p.second));
    }
    else
      tg.push_back(p);
  }

  swap(g, tg);
}

bool includeg(int x, vpii &g) {
  for (auto p: g)
    if (p.first <= x && x < p.second) return true;
  return false;
}

void printg(vpii g) {
  for (auto p: g) printf("(%d,%d) ", p.first, p.second);
  putchar('\n');
}

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) scanf("%d", as + i), as[i]--;
  for (int i = 0; i < q; i++) scanf("%d", bs + i), bs[i]--;

  gs[0].push_back(pii(0, n));

  for (int i = 0; i < q; i++) {
    vpii &g0 = gs[i], &g1 = gs[i + 1];

    int l = -1, r = -1;
    for (auto p: g0) {
      int li = p.first, ri = p.second;
      if (li > 0) li--;
      if (ri < n) ri++;

      if (l < 0) l = li, r = ri;
      else if (r < li) {
	g1.push_back(pii(l, r));
	l = li, r = ri;
      }
      else
	r = ri;
    }
    if (l >= 0) g1.push_back(pii(l, r));

    splitg(as[i], g1);
    splitg(bs[i], g1);

    if (g1.empty()) { puts("NO"); return 0; }
  }
  //for (int i = 0; i <= q; i++) printf("%d: ", i), printg(gs[i]);

  vs[q] = gs[q][0].first;
  for (int i = q - 1; i >= 0; i--) {
    int x = vs[i + 1];
    if (includeg(x, gs[i])) vs[i] = x;
    else if (x > 0 && includeg(x - 1, gs[i])) vs[i] = x - 1;
    else vs[i] = x + 1;
  }

  puts("YES");
  for (int i = 0; i <= q; i++) printf("%d\n", vs[i] + 1);
  return 0;
}
0