#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
vector<string> a[26];
int k[26];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
string s;
cin >> s;
a[s[0] - 'a'].push_back(s);
}
for (int i = 0; i < 26; ++i)
sort(a[i].begin(), a[i].end());
for (int i = 1; i <= m; ++i)
{
char u;
cin >> u;
cout << a[u - 'a'][k[u - 'a']] << endl;
++k[u - 'a'];
k[u - 'a'] %= a[u - 'a'].size();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
355 ms |
7928 KB |
Output is correct |
8 |
Correct |
345 ms |
7928 KB |
Output is correct |
9 |
Correct |
349 ms |
7932 KB |
Output is correct |
10 |
Correct |
350 ms |
8056 KB |
Output is correct |