結果

問題 No.1508 Avoid being hit
ユーザー wolgnikwolgnik
提出日時 2021-05-14 23:18:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,417 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 168,496 KB
最終ジャッジ日時 2024-04-10 03:27:31
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 35 ms
52,796 KB
testcase_02 AC 36 ms
53,480 KB
testcase_03 AC 33 ms
52,644 KB
testcase_04 AC 34 ms
52,748 KB
testcase_05 AC 34 ms
52,404 KB
testcase_06 AC 34 ms
53,992 KB
testcase_07 AC 34 ms
52,396 KB
testcase_08 AC 34 ms
53,424 KB
testcase_09 AC 33 ms
53,100 KB
testcase_10 AC 34 ms
53,132 KB
testcase_11 AC 34 ms
52,268 KB
testcase_12 AC 36 ms
53,712 KB
testcase_13 AC 33 ms
53,748 KB
testcase_14 AC 34 ms
52,200 KB
testcase_15 AC 34 ms
53,788 KB
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 AC 201 ms
168,496 KB
testcase_25 AC 191 ms
160,732 KB
testcase_26 AC 59 ms
75,360 KB
testcase_27 AC 129 ms
120,832 KB
testcase_28 AC 132 ms
121,180 KB
testcase_29 AC 197 ms
160,952 KB
testcase_30 AC 138 ms
124,308 KB
testcase_31 AC 181 ms
151,280 KB
testcase_32 AC 189 ms
157,600 KB
testcase_33 AC 90 ms
94,844 KB
testcase_34 AC 94 ms
97,568 KB
testcase_35 AC 62 ms
72,348 KB
testcase_36 AC 77 ms
85,152 KB
testcase_37 AC 53 ms
75,764 KB
testcase_38 AC 82 ms
91,932 KB
testcase_39 AC 75 ms
85,284 KB
testcase_40 AC 88 ms
99,752 KB
testcase_41 AC 67 ms
86,960 KB
testcase_42 AC 89 ms
99,844 KB
testcase_43 AC 98 ms
104,620 KB
testcase_44 AC 35 ms
52,140 KB
testcase_45 AC 35 ms
53,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, Q = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def simulate(x, i):
  if i == Q: return [x]
  if x != a[i] and x != b[i]:
    m = simulate(x, i + 1)
    if m != None:
      m.append(x)
      return m
  if x < N and x + 1 != a[i] and x + 1 != b[i]:
    r = simulate(x + 1, i + 1)
    if r != None:
      r.append(x)
      return r
  if x > 1 and x - 1 != a[i] and x - 1 != b[i]:
    l = simulate(x - 1, i + 1)
    if l != None:
      l.append(x)
      return l
  return None

if N <= 10:
  for x in range(1, N + 1):
    res = simulate(x, 0)
    if res != None:
      print("YES")
      res.reverse()
      for r in res: print(r)
      exit(0)
  print("NO")
else:
  res = [N // 2]
  x = N // 2
  for i in range(Q):
    if x != a[i] and x != b[i]:
      res.append(x)
      continue
    if x > N // 2:
      if x > 1 and x - 1 != a[i] and x - 1 != b[i]:
        res.append(x - 1)
        x -= 1
        continue
      if x < N and x + 1 != a[i] and x + 1 != b[i]:
        res.append(x + 1)
        x += 1
        continue
    else:
      if x < N and x + 1 != a[i] and x + 1 != b[i]:
        res.append(x + 1)
        x += 1
        continue
      if x > 1 and x - 1 != a[i] and x - 1 != b[i]:
        res.append(x - 1)
        x -= 1
        continue

  print("YES")
  for r in res: print(r)
0