結果

問題 No.1508 Avoid being hit
ユーザー wolgnikwolgnik
提出日時 2021-05-14 23:11:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 967 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 207,432 KB
最終ジャッジ日時 2024-10-02 04:21:02
合計ジャッジ時間 9,126 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from random import randint
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:
  while True:
    res = simulate(randint(1, N), 0)
    if res != None:
      print("YES")
      res.reverse()
      for r in res: print(r)
      exit(0)
0