結果

問題 No.3109 Swap members
ユーザー GOTKAKO
提出日時 2025-04-18 20:05:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 207,820 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2025-04-18 20:05:45
合計ジャッジ時間 7,818 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,K; cin >> N >> K;
    map<string,int> S;
    for(int i=0; i<N; i++){
        string s; cin >> s;
        S[s] = i;
    }
    vector<int> T(N);
    for(auto &t : T){
        string s; cin >> s;
        t = S[s];
    }

    vector<vector<int>> sepa(K);
    for(int i=0; i<N; i++) sepa.at(i%K).push_back(T.at(i));
    for(auto &s : sepa) sort(s.begin(),s.end());


    for(int i=0; i<N; i++){
        int p = i%K,q = i/K;
        if(sepa.at(p).at(q) == i) continue;
        cout << "No\n"; return 0;
    }
    cout << "Yes\n";
}
0