#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,q;cin>>n>>q;
vector<string>arr(n);
map<char,pair<ll,vector<string>>>ans;
for(auto &i:arr){
cin>>i;
char c=i[0];
ans[c].second.push_back(i);
}
for(char c='a';c<='z';c++)sort(ans[c].second.begin(),ans[c].second.end());
while(q--){
char c;cin>>c;
cout<<ans[c].second[ans[c].first]<<endl;
ll sz=ans[c].second.size();
ll x=ans[c].first+1;
x%=sz;
ans[c].first=x;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
280 ms |
10988 KB |
Output is correct |
8 |
Correct |
268 ms |
11028 KB |
Output is correct |
9 |
Correct |
277 ms |
11004 KB |
Output is correct |
10 |
Correct |
296 ms |
11004 KB |
Output is correct |