#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m, k, x; cin>>n>>m>>k>>x;
string t,s; cin>>t;
s.clear();
vector<char> v;
vector<string> q(m);
for(int i=0; i<m; i++)
{
cin>>s;
sort(s.begin(), s.end());
q[i]=s;
}
int l=1;
vector<int> poww(m+1);
poww[m-1]=1;
for(int i=m-2; i>=0; i--)
{
poww[i]=poww[i+1]*k;
if(poww[i]>1e9||poww[i]<0) poww[i]=-1;
}
for(int i=0; i<m; i++)
{
if(poww[i]==-1)
{
v.push_back(q[i][0]);
}
else
{
int p=(x-l)/poww[i];
l+=p*poww[i];
v.push_back(q[i][p]);
}
}
l=0;
for(int i=0; i<n; i++)
{
if(t[i]=='#')
{
t[i]=v[l];
l++;
}
}
cout<<t<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |