結果

問題 No.3109 Swap members
コンテスト
ユーザー Mistletoe
提出日時 2025-04-19 00:13:14
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 126 ms / 2,000 ms
+ 289µs
コード長 685 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 56 ms
コンパイル使用メモリ 14,464 KB
実行使用メモリ 35,024 KB
最終ジャッジ日時 2026-10-15 02:53:39
合計ジャッジ時間 8,165 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def solve():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N, K = map(int, data[idx:idx+2])
    idx +=2
    S = data[idx:idx+N]
    idx +=N
    T = data[idx:idx+N]
    
    # Check for each equivalence class modulo K
    for i in range(K):
        # Collect elements from S and T for positions i, i+K, i+2K, etc.
        s_group = []
        t_group = []
        pos = i
        while pos < N:
            s_group.append(S[pos])
            t_group.append(T[pos])
            pos += K
        # Check if the multisets are the same
        if sorted(s_group) != sorted(t_group):
            print("No")
            return
    print("Yes")

solve()
0