結果
問題 |
No.3109 Swap members
|
ユーザー |
|
提出日時 | 2025-04-18 21:10:53 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 306 ms / 2,000 ms |
コード長 | 1,112 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 64,904 KB |
最終ジャッジ日時 | 2025-04-18 21:11:03 |
合計ジャッジ時間 | 8,215 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
import sys from collections import defaultdict def main(): # Read input input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 K = int(input[ptr]) ptr += 1 S = input[ptr:ptr+N] ptr += N T = input[ptr:ptr+N] ptr += N # Create groups for S and T based on residue modulo K s_groups = defaultdict(list) t_groups = defaultdict(list) for i in range(N): pos = i + 1 # 1-based position r = pos % K s_groups[r].append(S[i]) for i in range(N): pos = i + 1 # 1-based position r = pos % K t_groups[r].append(T[i]) # Check each group for r in s_groups: if sorted(s_groups[r]) != sorted(t_groups.get(r, [])): print("No") return # Also check if T has any groups not present in S (though T is a permutation of S per problem statement) for r in t_groups: if sorted(t_groups[r]) != sorted(s_groups.get(r, [])): print("No") return print("Yes") if __name__ == "__main__": main()