Submission #2503147


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define N 5010
#define H 123
#define INF 0x7f7f7f7f
#define LL long long

LL len,k,cnt,nk=0,mark,a[N<<5],ans[6],kmax[6]={0};
char s[5010];

void print(LL x){
	if (x==0) return ;
	if (x<H) printf("%c",x);
	else {
		print((x-(x%H))/H);
		if (x%H) printf("c",x%H);
	}
}
int main()
{
	scanf("%s",s);
	scanf("%d",&k);
	LL mmax = 1;
	for (LL i=1;i<=5;i++) mmax*=H; 
	len = strlen(s);
	memset(a,0x7f7f7f7f,sizeof(a));
	for (int i=0;i<len;i++){
		a[++cnt] = (int)(s[i]);
		for (int j=1;i+j<len && j<=4;j++)
			a[++cnt] = a[cnt-1] *H + (int)(s[i+j]);
	}
	for (int i=1;i<=cnt;i++)
		while (a[i]<mmax) a[i]*=H;
	sort(a+1,a+cnt+1);
	for (int i=1;i<=cnt;i++){
		mark = 1;
		for (int j=1;j<=5;j++) 
			if (a[i]==kmax[j]) mark = 0;
		if (mark) kmax[++nk] = a[i];
		if (nk==k) break;
	}
	int x = 0;
	while (kmax[k]>0){
		ans[++x] = kmax[k]%H;
		kmax[k] = (kmax[k]-ans[x])/H;
	}
	for (int i=6;i>0;i--){
		if (ans[i]==0) break;
		printf("%c",ans[i]);
	}
	return 0;
}

Submission Info

Submission Time
Task C - K-th Substring
User nicous
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1104 Byte
Status AC
Exec Time 2 ms
Memory 1408 KB

Compile Error

./Main.cpp: In function ‘void print(long long int)’:
./Main.cpp:18:24: warning: format ‘%c’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
  if (x<H) printf("%c",x);
                        ^
./Main.cpp:21:26: warning: too many arguments for format [-Wformat-extra-args]
   if (x%H) printf("c",x%H);
                          ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:27:15: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
  scanf("%d",&k);
               ^
./Main.cpp:54:21: warning: format ‘%c’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   printf("%c",ans[i]);
                     ^
./Main.cpp:26:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s);
               ^
./Main.cpp:27:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute w...

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 3
AC × 11
AC × 19
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
Subtask 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 2_011.txt, 2_012.txt, 2_013.txt, 2_014.txt, 2_015.txt, 2_016.txt, 2_017.txt, 2_018.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 1408 KB
0_001.txt AC 1 ms 1408 KB
0_002.txt AC 1 ms 1408 KB
1_003.txt AC 1 ms 1408 KB
1_004.txt AC 1 ms 1408 KB
1_005.txt AC 1 ms 1408 KB
1_006.txt AC 1 ms 1408 KB
1_007.txt AC 1 ms 1408 KB
1_008.txt AC 1 ms 1408 KB
1_009.txt AC 1 ms 1408 KB
1_010.txt AC 1 ms 1408 KB
2_011.txt AC 2 ms 1408 KB
2_012.txt AC 2 ms 1408 KB
2_013.txt AC 2 ms 1408 KB
2_014.txt AC 2 ms 1408 KB
2_015.txt AC 2 ms 1408 KB
2_016.txt AC 2 ms 1408 KB
2_017.txt AC 2 ms 1408 KB
2_018.txt AC 2 ms 1408 KB