#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
cin>>n>>q;
set<pair<int,string>> wor[26];
for (int i=0;i<n;i++)
{
string s;
cin>>s;
wor[s[0]-'a'].insert({0,s});
}
while (q--)
{
char c;
cin>>c;
auto p=*wor[c-'a'].begin();
cout<<p.second<<endl;
wor[c-'a'].erase(p);
p.first++;
wor[c-'a'].insert(p);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
210 ms |
12220 KB |
Output is correct |
8 |
Correct |
218 ms |
12456 KB |
Output is correct |
9 |
Correct |
219 ms |
12368 KB |
Output is correct |
10 |
Correct |
231 ms |
12276 KB |
Output is correct |