結果
| 問題 |
No.3109 Swap members
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 00:01:13 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 440 ms / 2,000 ms |
| コード長 | 1,051 bytes |
| コンパイル時間 | 397 ms |
| コンパイル使用メモリ | 11,904 KB |
| 実行使用メモリ | 37,376 KB |
| 最終ジャッジ日時 | 2025-04-19 00:01:27 |
| 合計ジャッジ時間 | 12,433 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 52 |
ソースコード
def can_rearrange(n, k, s, t):
# Group positions by their remainder modulo K
groups = [[] for _ in range(k)]
for i in range(n):
groups[i % k].append(i)
# For each group, check if the characters in the source can be rearranged to match the target
for group in groups:
source_chars = [s[i] for i in group]
target_chars = [t[i] for i in group]
# Sort both lists to check if they contain the same elements
source_chars.sort()
target_chars.sort()
# If the sorted lists don't match, the rearrangement is impossible
if source_chars != target_chars:
return False
return True
def main():
# Read input
n, k = map(int, input().split())
s = []
for _ in range(n):
s.append(input())
t = []
for _ in range(n):
t.append(input())
# Check if rearrangement is possible
if can_rearrange(n, k, s, t):
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()