QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110277 | #4475. 重复 | xiaoyaowudi | 100 ✓ | 20ms | 30124kb | C++17 | 1.3kb | 2023-06-01 12:35:43 | 2023-06-01 12:35:45 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
constexpr int N(2010),p(998244353);
int fp(int a,int b){int ans(1),off(a);while(b){if(b&1) ans=1ll*ans*off%p;off=1ll*off*off%p;b>>=1;}return ans;}
int W(int k){return k>=p?k-p:k;}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);static char s[N];
int m;std::cin>>m>>(s+1);int n(std::strlen(s+1));
static int v1[N],v2[N],fl[N];
for(int i(2);i<=n;++i)
{
int j(fl[i-1]);while(j && s[j+1]!=s[i]) j=fl[j];
if(s[j+1]==s[i]) ++j;fl[i]=j;
}
for(int i(0);i<=n;++i)
{
int mx(-1),mp(0),v(i==n?fl[i]:i);
while(true)
{
if(s[v+1]-'a'+1>mx)
{
mx=s[v+1]-'a'+1;
mp=v+1;
}
if(!v) break;
v=fl[v];
}
// std::cerr<<i<<" "<<mx<<" "<<mp<<std::endl;
v2[i]=mp;v1[i]=26-mx;
}
int ans(0);
for(int i(1);i<=n;++i)
{
int u(i);
for(int j(1);j<=m && u;++j) u=v2[u];
if(u && u==i) ++ans;
}
static int f[N][N][2];f[0][0][0]=1;
for(int i(0);i<m;++i)
{
for(int j(0);j<=n;++j)
{
f[i+1][0][1]=(f[i+1][0][1]+1ll*f[i][j][1]*v1[j]+1ll*f[i][j][0]*v1[j]*(i+1))%p;
f[i+1][v2[j]][1]=W(f[i+1][v2[j]][1]+f[i][j][1]);
f[i+1][v2[j]][0]=W(f[i+1][v2[j]][0]+f[i][j][0]);
}
}
std::cout<<W(fp(26,m)-W(ans+f[m][0][1])+p)<<std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 2ms
memory: 3372kb
input:
5 utxpwmyovh
output:
11873600
result:
ok 1 number(s): "11873600"
Test #2:
score: 10
Accepted
time: 2ms
memory: 3564kb
input:
30 bhekhtazrdskusizkimkthaelctvab
output:
690391422
result:
ok 1 number(s): "690391422"
Test #3:
score: 10
Accepted
time: 1ms
memory: 3592kb
input:
50 flfsflfsflfsflfsflfs
output:
158554587
result:
ok 1 number(s): "158554587"
Test #4:
score: 10
Accepted
time: 2ms
memory: 3872kb
input:
85 ctiqhwibrrljvrsogddkjxtsoucmtqjducznwvslnjkpyjvamdnknyxslwowmewhcwkdqymljsshwljpandxjmswqukroyaydve
output:
767635094
result:
ok 1 number(s): "767635094"
Test #5:
score: 10
Accepted
time: 3ms
memory: 4512kb
input:
193 mtkbajqtvduekczyzxrbtkqikjzclxxmaqrntemikivczxlieyqpuwkkofoltttjtbmknbkxqhepnkvmgiwxwwravldcghnhrxlfbjgutuatjgkunafziudxvfzgarytoandeepptetgbfobufwdrfssqprtolqaubdagfgxkeqpcojrhthdgzswhidcnlnbf
output:
834222930
result:
ok 1 number(s): "834222930"
Test #6:
score: 10
Accepted
time: 4ms
memory: 5284kb
input:
300 gpqfkteejltpewqtpwxjdopigynimneadkrgdzbvdteebapyvwesbsqhgofqhlfxemrxykjzbiaqgcmuoopmrnbgcgzqjenpecjcainzisqdyqvqqulprhopucebwhlsilmnhzvjwxvjqsmgdmhwrefyugibvwxnixdmpfhwrtpnrltdcwctpcvccplfbtifipqnwnbf
output:
772953201
result:
ok 1 number(s): "772953201"
Test #7:
score: 10
Accepted
time: 3ms
memory: 8276kb
input:
300 oyczstbzwdszrmnxmledokfkvddpyfaodutuzogvlisopudyvohaxxonfcgcrhbsulufholejrspjxckplrqhrencahhiaqaounemkxvhzheangultnezzhtvaousltkauurapfgvvfhvradwkykqilhupxwtqutdqfsxmtfmzdddcxljxbmchsmrgpnysnuqparmrepgzuzpbiosfbabmawjpxpvzczlzfmntuvvcftgozdntwbdmrkvvxfvqkghvbdcguuoesvpxuyzapqbsdyhoddvfzvoptsjihq...
output:
251633039
result:
ok 1 number(s): "251633039"
Test #8:
score: 10
Accepted
time: 7ms
memory: 12940kb
input:
880 abelngddxylbyvkgrsbpdegqwohgshsrtxlxuwhgstkvzfeiqrjbopwwxiudovarjhxkdoewrbwcxfliemxsggkzvpfmlkeimsejvqhocmhpvimcpvwhtlqopvfngwnrmuwwjetcagedcgdwpjglpvyotlerqbaepbgbesbxqdnwckudhjfdhbqogohaireinbczffglyghnsvptzdurzwofybpjrzopkfxnlnmtaiqjnmbfuyjpcxtwicwxrovqixxqbsrzsqhzekzkyezwdsgxwdackzdrupfyyoct...
output:
893745577
result:
ok 1 number(s): "893745577"
Test #9:
score: 10
Accepted
time: 10ms
memory: 14688kb
input:
1998 bggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwt
output:
758188091
result:
ok 1 number(s): "758188091"
Test #10:
score: 10
Accepted
time: 20ms
memory: 30124kb
input:
2000 lvcmwzggyrdooanqnloalpaiuphxpfrozonodonneognbfgyzlumraoqbtstrpesciausnzqaiwxougtwohptrakhmujgdrahfewscrcdxycrtjenzvycwehnuovgbjdipjzaoiimehrpaxzhzqbnlbaigyzpwjppikbaqrcxwwvtyuuadmyadhmrdmaockaoocetpuavaveanykqfvsmixjwijumyjucltbzqfsefvrpjrnyotjhatirvgbeygxoiweoatiwecpsfigchrmbtldocttfgvqyicvkei...
output:
767010576
result:
ok 1 number(s): "767010576"
Extra Test:
score: 0
Extra Test Passed