結果

問題 No.2254 Reverse Only
ユーザー first_vilfirst_vil
提出日時 2023-03-24 22:23:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,232 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 155,616 KB
最終ジャッジ日時 2024-09-18 17:16:49
合計ジャッジ時間 10,239 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,992 KB
testcase_01 AC 43 ms
52,736 KB
testcase_02 AC 42 ms
52,608 KB
testcase_03 AC 43 ms
52,608 KB
testcase_04 AC 43 ms
52,608 KB
testcase_05 AC 44 ms
52,864 KB
testcase_06 AC 43 ms
52,864 KB
testcase_07 AC 44 ms
52,736 KB
testcase_08 WA -
testcase_09 AC 280 ms
142,020 KB
testcase_10 AC 135 ms
108,760 KB
testcase_11 AC 210 ms
115,148 KB
testcase_12 AC 206 ms
115,012 KB
testcase_13 AC 139 ms
108,484 KB
testcase_14 AC 210 ms
115,148 KB
testcase_15 AC 217 ms
116,136 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 208 ms
115,404 KB
testcase_19 WA -
testcase_20 AC 264 ms
141,528 KB
testcase_21 AC 259 ms
142,172 KB
testcase_22 AC 238 ms
150,652 KB
testcase_23 AC 247 ms
155,616 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 49 ms
61,312 KB
testcase_28 AC 163 ms
87,424 KB
testcase_29 AC 127 ms
104,832 KB
testcase_30 WA -
testcase_31 AC 84 ms
82,304 KB
testcase_32 AC 90 ms
85,248 KB
testcase_33 AC 67 ms
70,528 KB
testcase_34 AC 147 ms
104,320 KB
testcase_35 AC 115 ms
98,176 KB
testcase_36 AC 383 ms
129,452 KB
testcase_37 AC 367 ms
127,364 KB
testcase_38 AC 76 ms
76,928 KB
testcase_39 WA -
testcase_40 AC 50 ms
61,056 KB
testcase_41 AC 103 ms
92,928 KB
testcase_42 AC 78 ms
77,568 KB
testcase_43 AC 152 ms
101,760 KB
testcase_44 AC 201 ms
113,928 KB
testcase_45 WA -
testcase_46 AC 49 ms
60,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
# mod = int(1e9 + 7)
mod = 998244353


class dsu:
    n = 1
    parent_or_size = [-1 for i in range(n)]

    def __init__(self, N):
        self.n = N
        self.parent_or_size = [-1 for i in range(N)]

    def merge(self, a, b):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n)
        x = self.leader(a)
        y = self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n)
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        if self.parent_or_size[a] < 0:
            return a
        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        return -self.parent_or_size[self.leader(a)]

    def groups(self):
        leader_buf = [0 for i in range(self.n)]
        group_size = [0 for i in range(self.n)]
        for i in range(self.n):
            leader_buf[i] = self.leader(i)
            group_size[leader_buf[i]] += 1
        result = [[] for i in range(self.n)]
        for i in range(self.n):
            result[leader_buf[i]].append(i)
        result2 = []
        for i in range(self.n):
            if len(result[i]) > 0:
                result2.append(result[i])
        return result2


n, k = mi()
a = li()
b = li()
if a == b:
    print("Yes")
    exit()
if sorted(a) != sorted(b):
    print("No")
    exit()
if k <= 2:
    print("Yes")
    exit()
if k > n:
    print("No")
    exit()
if k == n:
    print("Yes" if a == b or a == b[::-1] else "No")
    exit()
uf = dsu(n)
for i in range(k + 1, n - 1):
    uf.merge(i, i - (k + 1))
    uf.merge(i, i + 1)
    uf.merge(n - 1 - i, n - 1 - i + k + 1)
    uf.merge(n - 1 - i, n - 1 - (i + 1))
if k == 3:
    for i in range(n - 2):
        uf.merge(i, i + 2)
sa = [list() for i in range(n)]
sb = [list() for i in range(n)]
for i in range(n):
    r = uf.leader(i)
    sa[r].append(a[i])
    sb[r].append(b[i])
ans = "Yes"
for i in range(n):
    if sorted(sa[i]) != sorted(sb[i]):
        ans = "No"
        break
if k == 3:
    print(ans)
    exit()
if ans == "No":
    r = uf.leader(0)
    x = [a[i] for i in range(n) if uf.leader(i) != r]
    y = [b[i] for i in range(n) if uf.leader(i) != r]
    if sorted(sa[r]) == sorted(sb[r]) and (x == y or x == y[::-1]):
        ans = "Yes"
print(ans)
0