Submission #2502078
Source Code Expand
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f
//0x3f3f3f3f
int aaaa,bbbb,cccc,dddd;
int f(){
aaaa++;
bbbb=cccc+dddd++;
return aaaa+bbbb;
}
const int MAXN = 200050, SIZE = 26;
struct SAM {
int len[MAXN], link[MAXN], next[MAXN][SIZE];
int total, last;
inline int newNode(int L) {
len[++total] = L; link[total] = 0;
for(int i = 0; i < SIZE; ++i) next[total][i] = 0;
return total;
}
inline void Add(int c) {
int i, p = last, cur = newNode(len[last] + 1);
for(; p && !next[p][c]; p = link[p]) next[p][c] = cur;
if(!p) link[cur] = 1;//令其指向初始状态
else {
int q = next[p][c];
if(len[q] == len[p] + 1) link[cur] = q;
else {//>
int clone = newNode(len[p] + 1);
for(i = 0; i < SIZE; ++i) next[clone][i] = next[q][i];
link[clone] = link[q];
link[q] = link[cur] = clone;
for(; p && next[p][c] == q; p = link[p]) next[p][c] = clone;
}
}
last = cur;
}
void Init () {//根节点是1
total = 0;
last = newNode(0);
}
}sam;
char str[MAXN];
int num[MAXN],idx[MAXN];
int dp[MAXN];
void solve(int k){
int now=1,L=0;
while(k){
for(int j=0;j<SIZE;j++){
if(sam.next[now][j]==0)
continue;
int x=sam.next[now][j];
if(k>dp[x])
k-=dp[x];
else{
str[L++]='a'+j;
now=x;
k--;
break;
}
}
}
str[L]='\0';
puts(str);
}
int main(){
int Q,k;
f();
aaaa++;
bbbb++;
scanf("%s",str);
f();
aaaa++;
bbbb++;
sam.Init();
f();
aaaa++;
bbbb++;
for(int i=0;str[i]!='\0';i++)
sam.Add(str[i]-'a');
f();
aaaa++;
bbbb++;
for(int i=1;i<=sam.total;i++)
num[i]=0;
f();
aaaa++;
bbbb++;
for(int i=1;i<=sam.total;i++)
num[sam.len[i]]++;
f();
aaaa++;
bbbb++;
for(int i=1;i<=sam.total;i++)
num[i]+=num[i-1];
f();
aaaa++;
bbbb++;
for(int i=1;i<=sam.total;i++)
idx[num[sam.len[i]]--]=i;
f();
aaaa++;
bbbb++;
for(int i=sam.total;i>=1;i--){
int now=idx[i];
dp[now]=1;
for(int j=0;j<SIZE;j++)
dp[now]+=dp[sam.next[now][j]];
}
scanf("%d",&k);
solve(k);
f();
aaaa++;
bbbb++;
return 0;
}
Submission Info
Submission Time
2018-05-12 22:05:43+0900
Task
C - K-th Substring
User
cscyuge
Language
C++14 (GCC 5.4.1)
Score
300
Code Size
4094 Byte
Status
AC
Exec Time
2 ms
Memory
4480 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:92:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",str);
^
./Main.cpp:134:31: 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
100 / 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
AC
2 ms
4352 KB
0_001.txt
AC
2 ms
4352 KB
0_002.txt
AC
2 ms
4352 KB
1_003.txt
AC
2 ms
4352 KB
1_004.txt
AC
2 ms
4352 KB
1_005.txt
AC
2 ms
4352 KB
1_006.txt
AC
2 ms
4352 KB
1_007.txt
AC
2 ms
4352 KB
1_008.txt
AC
2 ms
4352 KB
1_009.txt
AC
2 ms
4352 KB
1_010.txt
AC
2 ms
4352 KB
2_011.txt
AC
2 ms
4352 KB
2_012.txt
AC
2 ms
4352 KB
2_013.txt
AC
2 ms
4352 KB
2_014.txt
AC
2 ms
4480 KB
2_015.txt
AC
2 ms
4352 KB
2_016.txt
AC
2 ms
4480 KB
2_017.txt
AC
2 ms
4480 KB
2_018.txt
AC
2 ms
4480 KB