結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 35 ms
52,668 KB
testcase_02 AC 33 ms
53,760 KB
testcase_03 AC 37 ms
53,836 KB
testcase_04 AC 34 ms
53,288 KB
testcase_05 AC 34 ms
53,324 KB
testcase_06 AC 34 ms
52,984 KB
testcase_07 AC 36 ms
52,760 KB
testcase_08 AC 35 ms
53,284 KB
testcase_09 AC 34 ms
52,496 KB
testcase_10 AC 37 ms
52,736 KB
testcase_11 AC 35 ms
52,456 KB
testcase_12 AC 34 ms
53,216 KB
testcase_13 AC 36 ms
53,868 KB
testcase_14 AC 34 ms
53,564 KB
testcase_15 AC 34 ms
53,836 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 205 ms
167,860 KB
testcase_25 AC 194 ms
160,656 KB
testcase_26 AC 58 ms
75,048 KB
testcase_27 AC 132 ms
120,584 KB
testcase_28 AC 134 ms
120,788 KB
testcase_29 AC 189 ms
161,492 KB
testcase_30 AC 136 ms
124,960 KB
testcase_31 AC 179 ms
151,112 KB
testcase_32 AC 186 ms
157,928 KB
testcase_33 AC 89 ms
95,440 KB
testcase_34 AC 91 ms
97,340 KB
testcase_35 AC 61 ms
73,004 KB
testcase_36 AC 77 ms
85,308 KB
testcase_37 AC 53 ms
74,292 KB
testcase_38 AC 94 ms
91,796 KB
testcase_39 AC 76 ms
84,840 KB
testcase_40 AC 92 ms
99,932 KB
testcase_41 AC 69 ms
86,952 KB
testcase_42 AC 94 ms
100,204 KB
testcase_43 AC 100 ms
104,352 KB
testcase_44 AC 34 ms
53,612 KB
testcase_45 AC 34 ms
52,828 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 <= 100:
  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