結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 37 ms
53,808 KB
testcase_02 AC 36 ms
53,416 KB
testcase_03 AC 37 ms
53,972 KB
testcase_04 AC 36 ms
52,756 KB
testcase_05 AC 37 ms
52,444 KB
testcase_06 AC 37 ms
52,568 KB
testcase_07 AC 37 ms
54,084 KB
testcase_08 AC 37 ms
52,892 KB
testcase_09 AC 37 ms
52,684 KB
testcase_10 AC 36 ms
52,488 KB
testcase_11 AC 36 ms
52,624 KB
testcase_12 AC 37 ms
52,820 KB
testcase_13 AC 36 ms
53,532 KB
testcase_14 AC 38 ms
53,232 KB
testcase_15 AC 36 ms
53,144 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 223 ms
168,816 KB
testcase_25 AC 212 ms
160,728 KB
testcase_26 AC 65 ms
75,124 KB
testcase_27 AC 142 ms
120,836 KB
testcase_28 AC 145 ms
120,716 KB
testcase_29 AC 216 ms
160,608 KB
testcase_30 AC 148 ms
123,876 KB
testcase_31 AC 194 ms
151,168 KB
testcase_32 AC 204 ms
158,368 KB
testcase_33 AC 94 ms
94,808 KB
testcase_34 AC 97 ms
97,288 KB
testcase_35 AC 63 ms
71,296 KB
testcase_36 AC 81 ms
85,792 KB
testcase_37 AC 56 ms
74,488 KB
testcase_38 AC 87 ms
91,648 KB
testcase_39 AC 78 ms
85,100 KB
testcase_40 AC 98 ms
99,776 KB
testcase_41 AC 74 ms
87,224 KB
testcase_42 AC 100 ms
99,880 KB
testcase_43 AC 107 ms
104,284 KB
testcase_44 AC 37 ms
53,352 KB
testcase_45 AC 37 ms
52,560 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)
        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