# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22459 | 2017-04-30T04:52:04 Z | 크리님 제가 귀여우면 됬지 뭘 더 원하세요 진짜(#952, sys7961, hyorothy, skdudn321) | Joyful KMP (KRIII5_JK) | C++14 | 0 ms | 2028 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2028 KB | Output is correct |
2 | Incorrect | 0 ms | 2028 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |