結果
問題 | No.1508 Avoid being hit |
ユーザー |
![]() |
提出日時 | 2021-05-14 23:16:55 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,357 bytes |
コンパイル時間 | 348 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 167,296 KB |
最終ジャッジ日時 | 2024-10-02 04:47:31 |
合計ジャッジ時間 | 9,425 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 WA * 9 |
ソースコード
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)