結果
| 問題 |
No.1055 牛歩
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:33:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 900 bytes |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 82,968 KB |
| 実行使用メモリ | 142,840 KB |
| 最終ジャッジ日時 | 2025-03-20 20:34:23 |
| 合計ジャッジ時間 | 7,607 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 54 WA * 16 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
idx = 0
N = int(input[idx])
idx += 1
M = int(input[idx])
idx += 1
A = list(map(int, input[idx:idx+M]))
idx += M
Q = int(input[idx])
idx += 1
B = list(map(int, input[idx:idx+Q]))
pos = A.copy()
occupied = set(pos)
for b in B:
k = b - 1 # convert to 0-based index
x = pos[k]
right = x + 1
left = x - 1
right_ok = (right <= N) and (right not in occupied)
left_ok = (left >= 1) and (left not in occupied)
if right_ok:
new_pos = right
elif left_ok:
new_pos = left
else:
print("NO")
return
occupied.remove(x)
occupied.add(new_pos)
pos[k] = new_pos
print("YES")
if __name__ == "__main__":
main()
lam6er