結果

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

ソースコード

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