Submission #22348

# Submission time Handle Problem Language Result Execution time Memory
22348 2017-04-30T04:07:12 Z 크리콘 B번 문제는 그리디로 풀려요(#918, imsifile) Joyful KMP (KRIII5_JK) C++
0 / 7
0 ms 2108 KB
#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

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 time Memory Grader output
1 Correct 0 ms 2108 KB Output is correct
2 Incorrect 0 ms 2108 KB Output isn't correct
3 Halted 0 ms 0 KB -