# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208867 | Sensei | Tavan (COCI16_tavan) | C++14 | 5 ms | 504 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.
/*
DATE: 2020-03-12 14:04:45
NAME:
PROBLEM: COCI16_TAVAN
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
string st;
set<char> s[MAXN + 7];
long long suffe[MAXN + 7];
string dfs(int i, int mi, int x) {
if (i >= st.size()) {
return "";
}
if (st[i] != '#') {
return st[i] + dfs(i + 1, mi, x);
}
for (set<char>::iterator it = s[mi].begin(); it != s[mi].end(); it++) {
if (suffe[mi - 1] < x) {
x -= suffe[mi - 1];
continue;
}
else {
return *it + dfs(i + 1, mi - 1, x);
}
}
}
int main() {
int n, m, k, x;
cin >> n >> m >> k >> x;
cin >> st;
st.insert(st.begin(), '#');
for (int i = m; i >= 1; i--) {
string temp;
cin >> temp;
for (int j = 0; j < temp.size(); j++) {
s[i].insert(temp[j]);
}
}
suffe[0] = 1;
for (int i = 1; i <= m; i++) {
suffe[i] = suffe[i - 1] * s[i].size();
if (suffe[i] > x) {
suffe[i] = x + 1;
}
}
cout << dfs(1, m, x) << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |