Submission #2501771
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
int k,len,cnt,ji,ans,cnt1,x,len1;
char s[5020],s1[5020],res[5020];
struct node
{
int v[27];
node()
{
memset(v,-1,sizeof(v));
}
}t[10000001];
inline void build(int root)
{
x=root,len1=strlen(s1+1);
for(int i=1;i<=len1;i++)
{
int y=s1[i]-'a'+1;
if(t[x].v[y]==-1)
{
t[x].v[y]=++cnt1;
// cout<<s1[i]<<" "<<i<<" "<<y<<" "<<cnt1<<endl;
}
x=t[x].v[y];
}
}
void solve(int root)
{
int x=root,gg;
for(int j=1;j<=26;j++)
{
if(t[x].v[j]!=-1)
{
char ss=j+'a'-1;
// cout<<ss;
if(ji!=k)
++ji;
if(ji==k)
{
// printf("%c",ss);
res[++ans]=ss;
return;
}
gg=x;
x=t[x].v[j];
// cout<<x<<endl;
solve(x);
x=gg;
if(ji==k)
{
// printf("%c",ss);
res[++ans]=ss;
return;
}
}
}
}
int main()
{
scanf("%s",s+1);
scanf("%d",&k);
len=strlen(s+1);
for(int i=1;i<=len;i++)
{
cnt=0;
int ggg=strlen(s1+1);
for(int l=1;l<=ggg;l++)
s1[l]=0;
for(int j=i;j<=len;j++)
{
s1[++cnt]=s[j];
}
/* ggg=strlen(s1+1);
for(int l=1;l<=ggg;l++)
cout<<s1[l];
cout<<endl;*/
build(0);
}
solve(0);
for(int i=ans;i>=1;i--)
printf("%c",res[i]);
printf("\n");
return 0;
}
Submission Info
Submission Time
2018-05-12 22:01:00+0900
Task
C - K-th Substring
User
forever_shi
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
1473 Byte
Status
RE
Exec Time
486 ms
Memory
1054976 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:61:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+1);
^
./Main.cpp:62:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&k);
^
Judge Result
Set Name
Sample
Subtask
All
Score / Max Score
0 / 0
0 / 200
0 / 100
Status
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
MLE
266 ms
1054976 KB
0_001.txt
MLE
266 ms
1054976 KB
0_002.txt
MLE
266 ms
1054976 KB
1_003.txt
MLE
267 ms
1054976 KB
1_004.txt
MLE
267 ms
1054976 KB
1_005.txt
MLE
266 ms
1054976 KB
1_006.txt
MLE
267 ms
1054976 KB
1_007.txt
MLE
267 ms
1054976 KB
1_008.txt
MLE
266 ms
1054976 KB
1_009.txt
MLE
266 ms
1054976 KB
1_010.txt
MLE
266 ms
1054976 KB
2_011.txt
MLE
343 ms
1054976 KB
2_012.txt
MLE
343 ms
1054976 KB
2_013.txt
RE
484 ms
1054976 KB
2_014.txt
RE
486 ms
1054976 KB
2_015.txt
MLE
350 ms
1054976 KB
2_016.txt
RE
484 ms
1054976 KB
2_017.txt
RE
484 ms
1054976 KB
2_018.txt
RE
484 ms
1054976 KB