#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
signed main()
{
fast();
int k, n;
cin >> k >> n;
vector<int> cnt(26, 0);
vector<string> ok[26];
while(k--)
{
string life;
cin >> life;
ok[life[0]-'a'].pb(life);
cnt[life[0]-'a']++;
}
for(int i = 0; i < 26; i++)
sort(ok[i].begin(), ok[i].end());
vector<int> curr(26, 0);
while(n--)
{
char u;
cin >> u;
int num = u-'a';
cout << ok[num][curr[num]] << "\n";
curr[num]++;
curr[num]%=cnt[num];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
46 ms |
7856 KB |
Output is correct |
8 |
Correct |
52 ms |
7884 KB |
Output is correct |
9 |
Correct |
54 ms |
7852 KB |
Output is correct |
10 |
Correct |
45 ms |
7848 KB |
Output is correct |