結果
問題 |
No.1055 牛歩
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:54:35 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,482 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 125,920 KB |
最終ジャッジ日時 | 2025-03-31 17:56:05 |
合計ジャッジ時間 | 7,198 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 54 WA * 16 |
ソースコード
def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 M = int(data[idx]) idx += 1 A = list(map(int, data[idx:idx+M])) idx += M Q = int(data[idx]) idx += 1 B = list(map(lambda x: int(x)-1, data[idx:idx+Q])) # convert to zero-based indexes pos = A.copy() # current positions of each piece (sorted) possible = True for bi in B: if not possible: break i = bi current = pos[i] # Try moving right first new_pos = current + 1 valid_right = True if new_pos > N: valid_right = False else: if i > 0 and new_pos <= pos[i-1]: valid_right = False if i < M-1 and new_pos >= pos[i+1]: valid_right = False if valid_right: pos[i] = new_pos continue # Try moving left new_pos = current - 1 valid_left = True if new_pos < 1: valid_left = False else: if i > 0 and new_pos <= pos[i-1]: valid_left = False if i < M-1 and new_pos >= pos[i+1]: valid_left = False if valid_left: pos[i] = new_pos continue # Both directions invalid possible = False print("YES" if possible else "NO") if __name__ == '__main__': main()