#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;
priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> words[26];
int K, N;
int main(int argc, char **argv){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> K >> N;
for(int i = 0; i < K; ++i){
string Word; cin >> Word;
words[Word[0] - 'a'].push(mp(0, Word));
}
for(int i = 0; i < N; ++i){
char Letter; cin >> Letter;
pair<int, string> Top = words[Letter - 'a'].top();
words[Letter - 'a'].pop();
cout << Top.nd << endl;
words[Letter - 'a'].push(mp(Top.st+1, Top.nd));
}
return 0;
}
//cikisir
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
486 ms |
8728 KB |
Output is correct |
8 |
Correct |
494 ms |
8764 KB |
Output is correct |
9 |
Correct |
483 ms |
8608 KB |
Output is correct |
10 |
Correct |
472 ms |
8732 KB |
Output is correct |