码迷,mamicode.com
首页 > 其他好文 > 详细

[CERC 2008] Suffix reconstruction

时间:2019-04-27 13:09:54      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:type   putchar   code   style   std   div   read   tchar   include   

[题目链接]

         https://www.lydsy.com/JudgeOnline/problem.php?id=4319

[算法]

        首先 , 我们可以求出这个字符串的rank数组

        按照SA逐位枚举 , 贪心构造 , 即可

        时间复杂度 : O(N)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 5e6 + 10;

int n;
int sa[N] , rk[N];
char s[N];

template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == -) f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - 0;
    x *= f;
}
int main()
{
        
        read(n);
        for (int i = 1; i <= n; ++i)
        {
                read(sa[i]);
                rk[sa[i]] = i;        
        }
        s[sa[1]] = a;
        char now = a;
        for (int i = 2; i <= n; ++i)
        {
                if (rk[sa[i - 1] + 1] < rk[sa[i] + 1]) 
                        s[sa[i]] = now;
                else
                {
                        ++now;
                        if (now > z)
                        {
                                puts("-1");
                                return 0;        
                        }        
                        s[sa[i]] = now;
                }        
        }
        for (int i = 1; i <= n; ++i) putchar(s[i]);
        puts("");
        
        return 0;
    
}

 

[CERC 2008] Suffix reconstruction

标签:type   putchar   code   style   std   div   read   tchar   include   

原文地址:https://www.cnblogs.com/evenbao/p/10778128.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!