Submission #22348

#TimeUsernameProblemLanguageResultExecution timeMemory
22348크리콘 B번 문제는 그리디로 풀려요 (#40)Joyful KMP (KRIII5_JK)C++98
0 / 7
0 ms2108 KiB
#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)

JK.cpp: In function 'int main()':
JK.cpp:23:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s\n%lld", str, &K);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...