# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22385 | Lazy Against The Machine (#40) | Joyful KMP (KRIII5_JK) | C++14 | 0 ms | 2180 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;
string str;
bool yes[256];
char val[256];
int order;
__int128 fact[30];
vector<char> rem;
void recur(int idx, unsigned long long k)
{
if (idx == str.size())
{
printf("\n");
return;
}
if (val[str[idx]])
{
putchar(val[str[idx]]);
recur(idx + 1, k);
return;
}
for (int i = 0; i < rem.size(); i++)
{
if (k > fact[rem.size() - 1] / fact[rem.size() - order])
{
k -= fact[rem.size() - 1] / fact[rem.size() - order];
}
else
{
val[str[idx]] = rem[i];
--order;
rem.erase(rem.begin() + i);
putchar(val[str[idx]]);
recur(idx + 1, k);
return;
}
}
}
int main()
{
cin.sync_with_stdio(false);
cin >> str;
unsigned long long k;
cin >> k;
fact[0] = 1;
for (int i = 1; i <= 26; i++) fact[i] = i * fact[i - 1];
for (int i = 'a'; i <= 'z'; i++) rem.push_back(i);
for (char t : str)
{
if (yes[t]) continue;
yes[t] = true;
++order;
}
printf("%d\n", (int)(fact[26] / fact[26 - order] % 1000000007));
if (fact[26] / fact[26 - order] < k)
{
printf("OVER\n");
}
else
{
recur(0, k);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |