結果
| 問題 | 
                            No.3109 Swap members
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kakur41
                         | 
                    
| 提出日時 | 2025-04-20 03:55:22 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 197 ms / 2,000 ms | 
| コード長 | 2,444 bytes | 
| コンパイル時間 | 296 ms | 
| コンパイル使用メモリ | 12,288 KB | 
| 実行使用メモリ | 44,032 KB | 
| 最終ジャッジ日時 | 2025-04-20 03:55:30 | 
| 合計ジャッジ時間 | 7,019 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 52 | 
ソースコード
# coding: utf-8
import sys
from collections import defaultdict # defaultdict を使う別解も考えられるが、今回はリストで実装
def solve():
    # N と K を読み込む
    # Read N and K
    n, k = map(int, sys.stdin.readline().split())
    # 初期状態 S を読み込む (0-based index でアクセスするためリストに)
    # Read initial state S (into a list for 0-based indexing)
    s = [sys.stdin.readline().strip() for _ in range(n)]
    # 目標状態 T を読み込む (0-based index でアクセスするためリストに)
    # Read target state T (into a list for 0-based indexing)
    t = [sys.stdin.readline().strip() for _ in range(n)]
    # 各剰余グループ (0 から K-1) ごとにユーザーネームを格納するリストのリスト
    # List of lists to store usernames for each remainder group (0 to K-1)
    initial_groups = [[] for _ in range(k)]
    target_groups = [[] for _ in range(k)]
    # 初期状態 S を剰余グループに分類
    # Classify initial state S into remainder groups
    for i in range(n):
        remainder = i % k  # Calculate remainder using 0-based index
        initial_groups[remainder].append(s[i])
    # 目標状態 T を剰余グループに分類
    # Classify target state T into remainder groups
    for i in range(n):
        remainder = i % k  # Calculate remainder using 0-based index
        target_groups[remainder].append(t[i])
    # 各剰余グループについて、含まれるユーザーネームの集合が一致するかどうかを判定
    # For each remainder group, check if the set of usernames matches
    possible = True
    for r in range(k):
        # 各グループのリストをソートして比較する
        # Sort the lists for each group and compare them
        # ソートすることで、要素の集合が一致するかどうかを判定できる
        # Sorting allows checking if the sets of elements are identical
        if sorted(initial_groups[r]) != sorted(target_groups[r]):
            # 一致しないグループが見つかったら、不可能と判断してループを抜ける
            # If a mismatch is found, determine it's impossible and break the loop
            possible = False
            break
    # 結果を出力
    # Print the result
    if possible:
        print("Yes")
    else:
        print("No")
# 関数を実行
# Execute the function
solve()
            
            
            
        
            
kakur41