| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 22348 | 크리콘 B번 문제는 그리디로 풀려요 (#40) | Joyful KMP (KRIII5_JK) | C++98 | 0 ms | 2108 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
