#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define endl "\n"
#define Sara ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod=1e9+7;
const double PI=acos(-1);
// 1 2 3 --> 1,2,3 ...1,2..1,3..1..2,3..2..3..none (2 power number of elements)
//1 2 3 --> 2--> 1,2..1,3..2,3..(!n/(r!(n-r)!)) aka:ncr
// 1 2 3 -->2-->1,2..2,1..1,3..3,1..2,3..3,2..(n!/(n-r)!) aka:npr
//1 2 3--> 1..1,2..1,2,3..2..2,3..3 number of subarrays -->(n*(n+1))/2 "sum of numbers from 1 to n."
/*
ll power(ll x,ll y)
{
if(y==0)
return 1;
else if(y==1)
return x%mod;
ll r=power(x%mod,((y%mod)/2)%mod);
if(y%2==0)
return ((r%mod)*(r%mod));
else
return ((r%mod)*(r%mod)*(x%mod));
}
ll inverse(ll md,ll x)
{
return power(x%mod,mod-2);
}
*/
int main()
{
//freopen("input.in","r",stdin);
Sara
int k,n;
cin>>k>>n;
vector<string>v(k);
map<char,vector<string>>mp;
for(int i=0; i<k; i++)
{
cin>>v[i];
mp[v[i][0]].push_back(v[i]);
}
vector<char>c(n);
for(char i='a';i<='z';i++){
sort(mp[i].begin(),mp[i].end());
}
map<char,int>id;
for(char i='a';i<='z';i++){
id[i]=0;
}
for(int i=0; i<n; i++)
{
cin>>c[i];
int sz=mp[c[i]].size();
int now=id[c[i]];
if(now>=sz) id[c[i]]=0;
cout<<mp[c[i]][id[c[i]]]<<endl;
id[c[i]]++;
}
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 |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
71 ms |
11080 KB |
Output is correct |
8 |
Correct |
73 ms |
11076 KB |
Output is correct |
9 |
Correct |
71 ms |
11052 KB |
Output is correct |
10 |
Correct |
71 ms |
11104 KB |
Output is correct |