提交记录 6608


用户 题目 状态 得分 用时 内存 语言 代码长度
Moon 1006. 【模板题】后缀排序 Wrong Answer 0 275.922 ms 1864 KB C++ 1.43 KB
提交时间 评测时间
2018-10-30 20:16:51 2020-08-01 00:46:48
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define P pair<int ,int >
#define pb push_back
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
//#define int LL
using namespace std;
const int N   = 1e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)

struct suffix_array
{
	static const int M=300;
	int cnt[M],rk[N<<1],sa[N<<1],h[N<<1],n,m,p,i,j,k,tp[N<<1];
	int *x=rk,*y=tp;
	char str[N<<1];
	void Sort()
	{	
		memset(cnt,0,sizeof(cnt)) ;
		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)
		{
			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()
{
	scanf("%s",S.str+1);
	S.n=strlen(S.str+1);
	S.SA();
	rep(i,1,S.n)  printf("%d ",S.sa[i]);
	printf("\n");
	rep(i,2,S.n) printf("%d ",S.h[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #137.73 us56 KBWrong AnswerScore: 0

Subtask #1 Testcase #238.54 us56 KBAcceptedScore: 100

Subtask #1 Testcase #336.4 us56 KBAcceptedScore: 0

Subtask #1 Testcase #443.45 us56 KBAcceptedScore: 0

Subtask #1 Testcase #541.85 us56 KBAcceptedScore: 0

Subtask #1 Testcase #642.62 us56 KBAcceptedScore: 0

Subtask #1 Testcase #7275.922 ms1 MB + 448 KBRuntime ErrorScore: 0

Subtask #1 Testcase #8274.964 ms1 MB + 400 KBRuntime ErrorScore: -100

Subtask #1 Testcase #9274.982 ms1 MB + 376 KBRuntime ErrorScore: 0

Subtask #1 Testcase #10266.52 ms1 MB + 100 KBRuntime ErrorScore: 0

Subtask #1 Testcase #11266.461 ms1 MB + 148 KBRuntime ErrorScore: 0

Subtask #1 Testcase #12264.611 ms1 MB + 840 KBRuntime ErrorScore: 0

Subtask #1 Testcase #13184.557 ms1 MB + 788 KBRuntime ErrorScore: 0

Subtask #1 Testcase #14196.888 ms1 MB + 384 KBRuntime ErrorScore: 0

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

Subtask #1 Testcase #16264.945 ms1 MB + 568 KBRuntime ErrorScore: 0

Subtask #1 Testcase #17189.251 ms1 MB + 448 KBRuntime ErrorScore: 0

Subtask #1 Testcase #18191.702 ms1 MB + 412 KBRuntime ErrorScore: 0


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