# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22459 | 크리님 제가 귀여우면 됬지 뭘 더 원하세요 진짜 (#40) | Joyful KMP (KRIII5_JK) | C++14 | 0 ms | 2028 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 <stdio.h>
#include <stack>
#include <algorithm>
#include <string.h>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#define sz 100
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
bool check[30];
ll com[30][30],num[30];
vector<ll> vec;
void dfs(ll l,ll r,ll k) {
if (r == -1) return;
for (ll i = 0; i < 26; i++) {
if (check[i] == true) continue;
bool flag = false;
ll num = com[l][r];
for (ll j = 1; j <= r; j++) {
num *= j;
if (num >= k) {
flag = true;
break;
}
}
if (flag || k <= num) {
check[i] = true;
vec.push_back(i);
dfs(l - 1, r - 1, k);
return;
}
k -= num;
}
}
ll mod = 1000000007;
int main() {
memset(num, -1, sizeof(num));
string str; cin >> str;
ll cnt = 0;
for (ll i = 0; i < str.size(); i++)
if (num[str[i]-'a'] == -1)
num[str[i]-'a'] = cnt++;
ll k; scanf("%lld", &k);
com[0][0] = 1;
for (ll i = 1; i < 30; i++) {
com[i][0] = com[i][i] = 1;
for (ll j = 1; j < i; j++)
com[i][j] = com[i - 1][j - 1] + com[i - 1][j];
}
bool flag = false;
ll ans = com[26][cnt];
ll ans2 = com[26][cnt];
for (ll i = 1; i <= cnt; i++) {
ans *= i;
ans2 *= i;
if (ans >= k)
flag = true;
ans2 %= mod;
}
printf("%lld\n", ans2);
if (!flag) {
printf("OVER\n"); return 0;
}
dfs(25, cnt - 1, k);
for (ll i = 0; i < str.size(); i++) {
printf("%c", vec[num[str[i] - 'a']] + 'a');
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |