# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22348 | 크리콘 B번 문제는 그리디로 풀려요 (#40) | Joyful KMP (KRIII5_JK) | C++98 | 0 ms | 2108 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>
typedef long long lld;
lld comb[30][30], K;
int chk[26], chk2[26], cnt=1;
char str[1010101], repl[30];
void get_ord(int idx, lld ix){
if(idx > cnt)return;
for(repl[idx]='a'; repl[idx]<='z'; repl[idx]++){
if(chk2[repl[idx]-'a'])continue;
if(ix <= comb[26-idx][cnt-idx]){
chk2[repl[idx]-'a']=1;
get_ord(idx+1, ix);
break;
}
ix -= comb[26-idx][cnt-idx];
}
}
int main(){
scanf("%s\n%lld", str, &K);
comb[0][0]=1;
for(int i=1; i<=26; i++){
comb[i][0] = 1;
for(int j=1; j<=i; j++)comb[i][j] = comb[i][j-1] * (i+1-j);
}
for(int i=0; str[i]; i++){
if(!chk[str[i]-'a']) chk[str[i]-'a']=cnt++;
}
cnt--;
printf("%lld\n", comb[26][cnt]);
if(comb[26][cnt] < K) puts("OVER");
else{
get_ord(1, K);
for(int i=0; str[i]; i++){
int val = chk[str[i]-'a'];
putchar(repl[val]);
}
puts("");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |