#include <bits/stdc++.h>
using namespace std;
typedef pair<int,string> ps;
priority_queue<ps, vector<ps>, greater<ps> > pq;
int n, k, c[26];
vector<string> oc[26];
int main()
{
// freopen("doanchu.inp","r",stdin);
// freopen("doanchu.out","w",stdout);
// cin >> n >> k;
// for (int i = 1; i <= n; i++){
// string s;
// cin >> s; pq.push({0,s});
// }
// for (int i = 1 ; i <= k ; i++){
// char c;
// cin >> c;
// vector<ps> temp;
// while(!pq.empty()){
// if (pq.top().second[0]!=c) {temp.push_back(pq.top()); pq.pop();}
// else{
// string v = pq.top().second; int u = pq.top().first;
// cout << v << endl;
// pq.pop();
// pq.push({u+1,v});
// for (int i = 0; i < int(temp.size()); i++) pq.push(temp[i]);
// temp.clear();
// break;
// }
// }
// }
// return 0;
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i=0; i<n; ++i) {
string s;
cin >> s;
oc[s[0]-'a'].push_back(s);
}
for (int i=0; i<26; ++i)
sort(oc[i].begin(), oc[i].end());
while(k--) {
char a;
cin >> a;
int x=a-'a';
cout << oc[x][c[x]] << "\n";
c[x]=(c[x]+1)%oc[x].size();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
57 ms |
6192 KB |
Output is correct |
8 |
Correct |
58 ms |
6236 KB |
Output is correct |
9 |
Correct |
58 ms |
6324 KB |
Output is correct |
10 |
Correct |
57 ms |
6220 KB |
Output is correct |