提交记录 6626


用户 题目 状态 得分 用时 内存 语言 代码长度
Moon 1006. 【模板题】后缀排序 Wrong Answer 0 211.222 ms 1504 KB C++ 1.17 KB
提交时间 评测时间
2018-10-30 20:38:39 2020-08-01 00:47:40
//include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring> 
#define rep(i,x,y) for (int i=x;i<=y;++i)
using namespace std;
const int N  =  4e5+233;
//const int mod = ;
struct Suffix_Array
{
	static const int M=300;
	int rk[N],tp[N],cnt[M],sa[N],h[N],n,m,p,i,j,k;
	int *x=rk,*y=tp;
	char str[N];
	inline void Init()
	{
		scanf("%s",str+1);
		n=strlen(str+1);
	}
	void Sort()
	{	
		//memset(cnt,0,sizeof(cnt)) ;
		rep(i,0,m) cnt[i]=0;
		rep(i,1,n) ++cnt[x[y[i]]];
		rep(i,1,m) cnt[i]+=cnt[i-1];
		for (int i=n;i>=1;--i)sa[ cnt[x[y[i]]]--] =y[i];
	}
	int cmp(int *f,int x,int y,int w){return f[x]==f[y]&&f[x+w]==f[y+w];}
	void SA()
	{
		rep(i,1,n) x[i]=str[i],y[i]=i;
		m=256;Sort();
		for (int w=1;w<=n;w<<=1,m=p)
		{
			p=0;
			rep(i,n-w+1,n) y[++p]=i;
			rep(i,1,n) if (sa[i]>w) y[++p]=sa[i]-w;
			Sort();
			swap(x,y);
			x[sa[1]]=p=1;
			rep(i,2,n) 
			  x[sa[i]]=cmp(y,sa[i],sa[i-1],w) ?p :++p;
		}
		rep(i,1,n) rk[sa[i]]=i;
		int j,k=0;
		for (int i=1;i<=n;h[rk[i++]]=k)
		  for (k ? --k :0,j=sa[rk[i] -1];  str[j+k]==str[i+k];++k);
	}
}S;
signed main()
{
	S.Init();
	S.SA()	;
	rep(i,1,S.n) printf("%d ",S.sa[i]);puts("");
	rep(i,2,S.n) printf("%d ",S.h[i]) ;
	return 0;	
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #111.67 us40 KBWrong AnswerScore: 0

Subtask #1 Testcase #212.09 us40 KBAcceptedScore: 100

Subtask #1 Testcase #311.98 us40 KBAcceptedScore: 0

Subtask #1 Testcase #416.73 us40 KBAcceptedScore: 0

Subtask #1 Testcase #516.55 us40 KBAcceptedScore: 0

Subtask #1 Testcase #616.91 us40 KBAcceptedScore: 0

Subtask #1 Testcase #7211.222 ms1 MB + 360 KBRuntime ErrorScore: -100

Subtask #1 Testcase #8195.857 ms1 MB + 352 KBRuntime ErrorScore: 0

Subtask #1 Testcase #9195.85 ms1 MB + 340 KBRuntime ErrorScore: 0

Subtask #1 Testcase #10187.584 ms1 MB + 112 KBRuntime ErrorScore: 0

Subtask #1 Testcase #11187.523 ms1 MB + 96 KBRuntime ErrorScore: 0

Subtask #1 Testcase #12184.125 ms1 MB + 480 KBRuntime ErrorScore: 0

Subtask #1 Testcase #13185.415 ms1 MB + 364 KBRuntime ErrorScore: 0

Subtask #1 Testcase #14193.083 ms1 MB + 408 KBRuntime ErrorScore: 0

Subtask #1 Testcase #15192.556 ms1 MB + 388 KBRuntime ErrorScore: 0

Subtask #1 Testcase #16185.576 ms1 MB + 380 KBRuntime ErrorScore: 0

Subtask #1 Testcase #176.395 ms1 MB + 348 KBRuntime ErrorScore: 0

Subtask #1 Testcase #18187.474 ms1 MB + 396 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-09 19:16:03 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠