QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780089#9747. 字符串复制Nlll#TL 2ms11824kbC++172.2kb2024-11-25 00:49:392024-11-25 00:49:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-25 00:49:40]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:11824kb
  • [2024-11-25 00:49:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn = 2e6 + 5;
const ll P = 998244353;
struct node{
    int len, fa;
    int s[26];
};
struct SAM{
    int n,lst=1,cnt=1;
    char s[Maxn];
    ll ans[Maxn << 1];
    node a[Maxn << 1];
    void ins(int c)
    {
	    int p=lst,np=lst=++cnt;a[np].len=a[p].len+1;
	    for(;p&&!a[p].s[c];p=a[p].fa) a[p].s[c]=np;
	    if(!p) return(void)(a[np].fa=1);
	    int q=a[p].s[c];
	    if(a[q].len==a[p].len+1) return(void)(a[np].fa=q);
	    int nq=++cnt;a[nq]=a[q],a[nq].len=a[p].len+1,a[q].fa=a[np].fa=nq;
	    for(;p&&a[p].s[c]==q;p=a[p].fa) a[p].s[c]=nq;
    }
    ll dfs(int x)
    {
	    //if(ans[x]) return ans[x];
	    ans[x] = 0;
        for(int i=0;i<26;i++)
        {
            if(a[x].s[i])
            {
                ans[x] = (ans[x] + dfs(a[x].s[i]) + 1) % P;
            }
        }
	    return ans[x];
    }
    ll num()
    {
        return dfs(1);
    }
    void ins(string s)
    {
        for(int i = 0; i < s.length(); i++)
        {
            ins(s[i] - 'a');
        }
    }
    /*
    void clear(int x)
    {
        ans[x] = 0;
        for(int i=0;i<26;i++)
        {
            if(a[x].s[i])
            {
                clear(a[x].s[i]);
            }
        }
    }
    */
};
SAM S, SS, SSS, tmp;
void solve()
{
    int n;
    ll m;
    cin >> n >> m;
    string s;
    cin >> s;
    S.ins(s);
    ll ans = 0;
    if(m == 1)
    {
        ans = S.num();
    }
    else
    {
        ll x = S.num();
        //S.clear(1);
        S.ins(s);
        ll y = S.num();
        ll z = 0;
        int now = 2;
        if(m > 2)
        {
            while(1)
            {
                //S.clear(1);
                S.ins(s);
                z = S.num();
                now++;
                if((z + x - y * 2) % P == 0 || now == 10)
                {
                    break;
                }
                x = y;
                y = z;
            }
            ans = ((z - y) * (m - now) % P + z) % P;
        }
        else ans = y;
    }
    cout << ans << "\n";
}
int main()
{
	cin.tie(0)->sync_with_stdio(false);
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 11776kb

input:

6 2
mantle

output:

57

result:

ok single line: '57'

Test #2:

score: 0
Accepted
time: 2ms
memory: 11824kb

input:

12 1919810
ifamjlifamjl

output:

138226305

result:

ok single line: '138226305'

Test #3:

score: 0
Accepted
time: 0ms
memory: 11696kb

input:

13 935330878
aabbbbababbaa

output:

348310505

result:

ok single line: '348310505'

Test #4:

score: -100
Time Limit Exceeded

input:

300000 1000000000
rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...

output:


result: