結果
問題 |
No.3109 Swap members
|
ユーザー |
|
提出日時 | 2025-04-18 21:19:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 192 ms / 2,000 ms |
コード長 | 1,040 bytes |
コンパイル時間 | 1,350 ms |
コンパイル使用メモリ | 89,476 KB |
実行使用メモリ | 43,928 KB |
最終ジャッジ日時 | 2025-04-18 21:19:11 |
合計ジャッジ時間 | 7,232 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
コンパイルメッセージ
main.cpp: In function ‘bool can_rearrange(int, int, const std::vector<std::__cxx11::basic_string<char> >&, const std::vector<std::__cxx11::basic_string<char> >&)’: main.cpp:19:20: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 19 | for (auto& [_, str] : s_groups[i]) s_vec.push_back(str); | ^ main.cpp:20:20: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 20 | for (auto& [_, str] : t_groups[i]) t_vec.push_back(str); | ^
ソースコード
#include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> using namespace std; bool can_rearrange(int N, int K, const vector<string>& S, const vector<string>& T) { vector<multimap<int, string>> s_groups(K), t_groups(K); for (int i = 0; i < N; ++i) { s_groups[i % K].insert({i % K, S[i]}); t_groups[i % K].insert({i % K, T[i]}); } for (int i = 0; i < K; ++i) { vector<string> s_vec, t_vec; for (auto& [_, str] : s_groups[i]) s_vec.push_back(str); for (auto& [_, str] : t_groups[i]) t_vec.push_back(str); sort(s_vec.begin(), s_vec.end()); sort(t_vec.begin(), t_vec.end()); if (s_vec != t_vec) return false; } return true; } int main() { int N, K; cin >> N >> K; vector<string> S(N), T(N); for (int i = 0; i < N; ++i) cin >> S[i]; for (int i = 0; i < N; ++i) cin >> T[i]; if (can_rearrange(N, K, S, T)) { cout << "Yes\n"; } else { cout << "No\n"; } return 0; }