結果

問題 No.3109 Swap members
ユーザー aaaaaaaaaaa
提出日時 2025-04-18 22:51:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 32,844 KB
最終ジャッジ日時 2025-04-18 22:51:07
合計ジャッジ時間 4,943 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // For std::sort

int main() {
    // 提高I/O速度
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int N;
    int K;
    std::cin >> N >> K;

    std::vector<std::string> S(N);
    std::vector<std::string> T(N);

    for (int i = 0; i < N; ++i) {
        std::cin >> S[i];
    }
    for (int i = 0; i < N; ++i) {
        std::cin >> T[i];
    }

    // 创建 K 个 vector,分别存储 S 和 T 中索引对 K 的余数相同的字符串
    std::vector<std::vector<std::string>> s_groups(K);
    std::vector<std::vector<std::string>> t_groups(K);

    for (int i = 0; i < N; ++i) {
        s_groups[i % K].push_back(S[i]);
        t_groups[i % K].push_back(T[i]);
    }

    // 对每个组内的字符串列表进行排序
    for (int r = 0; r < K; ++r) {
        std::sort(s_groups[r].begin(), s_groups[r].end());
        std::sort(t_groups[r].begin(), t_groups[r].end());
    }

    // 比较排序后的列表
    bool possible = true;
    for (int r = 0; r < K; ++r) {
        if (s_groups[r] != t_groups[r]) {
            possible = false;
            break;
        }
    }

    if (possible) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}
0