結果

問題 No.2254 Reverse Only
ユーザー lam6er
提出日時 2025-04-15 23:09:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 146,820 KB
最終ジャッジ日時 2025-04-15 23:11:26
合計ジャッジ時間 7,349 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    k = int(input[ptr])
    ptr += 1
    A = list(map(int, input[ptr:ptr+N]))
    ptr += N
    B = list(map(int, input[ptr:ptr+N]))
    ptr += N

    # Check if A and B are permutations
    count = defaultdict(int)
    for x in A:
        count[x] += 1
    for x in B:
        count[x] -= 1
        if count[x] < 0:
            print("No")
            return

    if k == 1:
        print("Yes")
        return

    if k > N:
        if A == B or A[::-1] == B:
            print("Yes")
        else:
            print("No")
        return

    if k % 2 == 0:
        print("Yes")
    else:
        if N >= k + 1:
            print("Yes")
        else:
            if A == B or A[::-1] == B:
                print("Yes")
            else:
                print("No")

if __name__ == "__main__":
    main()
0