# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94143 | MrTEK | Tavan (COCI16_tavan) | C++14 | 2 ms | 548 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
const int N = 5e3 + 5;
string s,ans,t[N];
int n,m,k,x;
bool ok[N];
ll suff[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> k >> x >> s;
for (int i = 1 ; i <= m ; i++) {
cin >> t[i];
sort(t[i].begin(),t[i].end());
t[i].resize(unique(t[i].begin(),t[i].end()) - t[i].begin());
}
suff[m + 1] = 1;
for (int i = m ; i >= 1 ; i--) {
suff[i] = suff[i + 1] * t[i].size();
if (ok[i + 1] || suff[i] > x)
ok[i] = true;
}
int lst = 0;
for (int i = 0 ; i < n ; i++) {
if (s[i] == '#') {
lst++;
int p = 0;
while(!ok[lst + 1] && p < t[lst].size() && suff[lst + 1] < x) {
x -= suff[lst + 1];
p++;
}
ans.push_back(t[lst][p]);
}
else
ans.push_back(s[i]);
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |