Submission #2605831


Source Code Expand

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int S=5005,N=2*S;
int st[N],ch[N][30],fa[N],len[N],tot=1,last=1,k;
char str[S];
void build(int c,int id)
{
	int np=++tot,p=last;
	for(;p&&!ch[p][c];p=fa[p])	ch[p][c]=np;
	if(!p)	fa[np]=1;
	else
	{
		int q=ch[p][c];
		if(len[p]+1==len[q])	fa[np]=q;
		else
		{
			int nq=++tot;len[nq]=len[p]+1;
			memcpy(ch[nq],ch[q],sizeof(ch[q]));fa[nq]=fa[q];
			fa[np]=fa[q]=nq;
			for(;p&&ch[p][c]==q;p=fa[p])	ch[p][c]=nq;
		}
	}
	len[np]=id;last=np;
}
void gg()
{
	for(int i=1;i<=st[0];i++)	putchar(st[i]+'a');
	exit(0);
}
void dfs(int x)
{
	k--;
	if(!k)	gg();
	for(int i=0;i<26;i++)
		if(ch[x][i])
		{
			st[++st[0]]=i;
			dfs(ch[x][i]);
			st[0]--;
		}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",str+1);
	k=ri()+1;
	int len=strlen(str+1),i;
	for(i=1;i<=len;i++)	build(str[i]-'a',i);
	dfs(1);
	return 0;
}
/*
atcoderandatcodeer
5



*/

Submission Info

Submission Time
Task C - K-th Substring
User jyz1232012
Language C++ (GCC 5.4.1)
Score 300
Code Size 1398 Byte
Status AC
Exec Time 2 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:65:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str+1);
                   ^

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 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 1 ms 256 KB
1_009.txt AC 1 ms 256 KB
1_010.txt AC 1 ms 256 KB
2_011.txt AC 2 ms 896 KB
2_012.txt AC 2 ms 896 KB
2_013.txt AC 2 ms 1024 KB
2_014.txt AC 2 ms 1024 KB
2_015.txt AC 2 ms 896 KB
2_016.txt AC 2 ms 1024 KB
2_017.txt AC 2 ms 1024 KB
2_018.txt AC 2 ms 1024 KB