Submission #2501789


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[9000001];
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
Task C - K-th Substring
User forever_shi
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1472 Byte
Status RE
Exec Time 452 ms
Memory 949504 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 200 / 200 0 / 100
Status
AC × 3
AC × 11
AC × 14
RE × 5
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 243 ms 949504 KB
0_001.txt AC 242 ms 949504 KB
0_002.txt AC 241 ms 949504 KB
1_003.txt AC 241 ms 949504 KB
1_004.txt AC 243 ms 949504 KB
1_005.txt AC 242 ms 949504 KB
1_006.txt AC 241 ms 949504 KB
1_007.txt AC 242 ms 949504 KB
1_008.txt AC 242 ms 949504 KB
1_009.txt AC 241 ms 949504 KB
1_010.txt AC 241 ms 949504 KB
2_011.txt AC 320 ms 949504 KB
2_012.txt AC 319 ms 949504 KB
2_013.txt RE 452 ms 949504 KB
2_014.txt RE 448 ms 949504 KB
2_015.txt AC 327 ms 949504 KB
2_016.txt RE 449 ms 949504 KB
2_017.txt RE 450 ms 949504 KB
2_018.txt RE 448 ms 949504 KB