#include<bits/stdc++.h>
using namespace std;
int n,m;
vector <string> v[26];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++){
string input;
cin >> input;
v[input[0] - 'a'].push_back(input);
}
for(int i = 0; i < 26; i++){
sort(v[i].begin(), v[i].end());
}
for(int i = 0; i < m; i++){
char slovo;
cin >> slovo;
string output = v[slovo - 'a'][0];
cout << output << endl;
v[slovo - 'a'].erase(v[slovo - 'a'].begin());
v[slovo - 'a'].push_back(output);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Execution timed out |
2040 ms |
6088 KB |
Time limit exceeded |
8 |
Execution timed out |
2035 ms |
6088 KB |
Time limit exceeded |
9 |
Execution timed out |
2047 ms |
6176 KB |
Time limit exceeded |
10 |
Execution timed out |
2043 ms |
6176 KB |
Time limit exceeded |