#include <bits/stdc++.h>
using namespace std;
vector<string> A[26];
int n, m, cnt[26];
int main() {
cin >> n >> m;
while(n--) {
string ret; cin >> ret;
A[ret[0]-'a'].emplace_back(ret);
}
for(int i = 0; i < 26; ++i) sort(A[i].begin(), A[i].end());
while(m--) {
char c; cin >> c;
cout << A[c-'a'][cnt[c-'a']] << endl;
cnt[c-'a'] = (cnt[c-'a'] + 1) % A[c-'a'].size();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
341 ms |
8056 KB |
Output is correct |
8 |
Correct |
335 ms |
7928 KB |
Output is correct |
9 |
Correct |
349 ms |
7928 KB |
Output is correct |
10 |
Correct |
348 ms |
7928 KB |
Output is correct |