#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0)
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
ll n,m;
cin>>n>>m;
map<char,vector<string>>mp;
string s;
vector<string>t(n);
for(int i=0; i<n; ++i){
cin>>t[i];
mp[t[i][0]].push_back(t[i]);
}
for(char i ='a'; i<='z'; ++i){
sort(mp[i].begin(),mp[i].end());
}
char y;
vector<int>freq(26,0);
for(int i=0; i<m; ++i){
cin>>y;
int f = (int)y-'a';
cout<<mp[y][freq[f]%mp[y].size()]<<endl;
++freq[f];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
227 ms |
11008 KB |
Output is correct |
8 |
Correct |
212 ms |
10948 KB |
Output is correct |
9 |
Correct |
237 ms |
11164 KB |
Output is correct |
10 |
Correct |
229 ms |
11032 KB |
Output is correct |