結果

問題 No.1508 Avoid being hit
ユーザー wolgnikwolgnik
提出日時 2021-05-14 23:16:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 167,168 KB
最終ジャッジ日時 2024-04-10 03:23:39
合計ジャッジ時間 8,255 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
52,548 KB
testcase_02 AC 41 ms
52,480 KB
testcase_03 AC 40 ms
52,352 KB
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 40 ms
52,224 KB
testcase_06 AC 40 ms
52,480 KB
testcase_07 AC 40 ms
52,480 KB
testcase_08 AC 41 ms
52,224 KB
testcase_09 AC 39 ms
52,736 KB
testcase_10 AC 40 ms
52,736 KB
testcase_11 AC 39 ms
52,224 KB
testcase_12 AC 40 ms
52,480 KB
testcase_13 AC 41 ms
52,480 KB
testcase_14 AC 40 ms
51,968 KB
testcase_15 AC 40 ms
51,968 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 224 ms
167,168 KB
testcase_25 AC 210 ms
159,156 KB
testcase_26 AC 67 ms
73,728 KB
testcase_27 AC 145 ms
120,320 KB
testcase_28 AC 146 ms
120,704 KB
testcase_29 AC 208 ms
160,640 KB
testcase_30 AC 152 ms
123,904 KB
testcase_31 AC 201 ms
151,040 KB
testcase_32 AC 215 ms
157,440 KB
testcase_33 AC 98 ms
94,464 KB
testcase_34 AC 102 ms
97,792 KB
testcase_35 AC 65 ms
71,296 KB
testcase_36 AC 83 ms
85,352 KB
testcase_37 AC 60 ms
73,472 KB
testcase_38 AC 91 ms
92,032 KB
testcase_39 AC 85 ms
84,864 KB
testcase_40 AC 110 ms
100,324 KB
testcase_41 AC 77 ms
86,912 KB
testcase_42 AC 101 ms
99,852 KB
testcase_43 AC 108 ms
104,708 KB
testcase_44 AC 40 ms
52,480 KB
testcase_45 AC 40 ms
52,352 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)
        continue
      if x < N and x + 1 != a[i] and x + 1 != b[i]:
        res.append(x + 1)
        continue
    else:
      if x < N and x + 1 != a[i] and x + 1 != b[i]:
        res.append(x + 1)
        continue
      if x > 1 and x - 1 != a[i] and x - 1 != b[i]:
        res.append(x - 1)
        continue
  print("YES")
  for r in res: print(r)
0