結果

問題 No.2254 Reverse Only
ユーザー gew1fw
提出日時 2025-06-12 21:19:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 160,792 KB
最終ジャッジ日時 2025-06-12 21:19:40
合計ジャッジ時間 7,625 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    k = int(input[idx])
    idx +=1
    A = list(map(int, input[idx:idx+N]))
    idx += N
    B = list(map(int, input[idx:idx+N]))
    
    # Check if A and B are permutations
    if sorted(A) != sorted(B):
        print("No")
        return
    
    if k <= 2:
        print("Yes")
        return
    elif k > N:
        if A == B:
            print("Yes")
        else:
            print("No")
        return
    else:
        # Check if N >= 2*k -2
        if N >= 2*k - 2:
            print("Yes")
            return
        else:
            # Check first k-1 elements and last k-1 elements
            same = True
            # Check first k-1 elements
            for i in range(k-1):
                if A[i] != B[i]:
                    same = False
                    break
            if same:
                # Check last k-1 elements
                for i in range(N - (k-1), N):
                    if A[i] != B[i]:
                        same = False
                        break
            if same:
                print("Yes")
            else:
                print("No")
            return

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