QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322235 | #8223. 字符串游戏 | zhouhuanyi | 15 | 579ms | 264556kb | C++20 | 2.1kb | 2024-02-06 16:23:11 | 2024-02-06 16:23:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<map>
#include<cstdlib>
#include<random>
#define N 2000000
#define M 25000000
#define K 16777215
#define Base1 131
#define Base2 171
#define mod1 998244353
#define mod2 998244853
using namespace std;
mt19937 RAND(random_device{}());
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int MD1(int x)
{
return x>=mod1?x-mod1:x;
}
int MD2(int x)
{
return x<0?x+mod1:x;
}
int MD3(int x)
{
return x>=mod2?x-mod2:x;
}
int MD4(int x)
{
return x<0?x+mod2:x;
}
struct reads
{
int hsh1,hsh2;
bool operator == (const reads &t)const
{
return hsh1==t.hsh1&&hsh2==t.hsh2;
}
};
reads rd[26],zero;
reads operator + (reads a,reads b)
{
return (reads){MD1(a.hsh1+b.hsh1),MD2(a.hsh2+b.hsh2)};
}
reads operator - (reads a,reads b)
{
return (reads){MD3(a.hsh1-b.hsh1),MD4(a.hsh2-b.hsh2)};
}
reads operator * (reads a,reads b)
{
return (reads){1ll*a.hsh1*b.hsh1%mod1,1ll*a.hsh2*b.hsh2%mod2};
}
struct node
{
reads num;
int data,nxt;
};
node edge[M+1];
string s;
int len,head[K+1],dp[N+1];
void adder(reads x,int d)
{
int ds=(x.hsh1^x.hsh2)&K;
for (int i=head[ds];i>0;i=edge[i].nxt)
if (edge[i].num==x)
{
edge[i].data+=d;
return;
}
edge[++len]=(node){x,d,head[ds]},head[ds]=len;
return;
}
int query(reads x)
{
int ds=(x.hsh1^x.hsh2)&K;
for (int i=head[ds];i>0;i=edge[i].nxt)
if (edge[i].num==x)
return edge[i].data;
return 0;
}
int main()
{
bool op=1;
reads res;
for (int i=0;i<26;++i) rd[i]=(reads){(int)(RAND()%mod1),(int)(RAND()%mod2)};
cin>>s;
if (s.length()<=5000) len=s.length();
else len=25;
for (int i=0;i<s.length();++i) op&=(s[i]==s[0]);
if (op)
{
printf("%d\n",(s.length()+1)>>1);
return 0;
}
for (int i=s.length();i>=1;--i)
{
res=zero;
for (int j=1;j<=len&&i+j-1<=s.length();++j) res=res*(reads){Base1,Base2}+rd[s[i+j-2]-'a'],adder(res,1),dp[i]=max(dp[i],query(res)-dp[i+j]);
}
printf("%d\n",dp[1]);
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 570ms
memory: 263892kb
input:
abbabbbbabbaaaaabbbaabaaaaaabbbaabbabababaabababaababaaaaaabaaabaaabbbbababaaabbbabababbbabbbaabaaababbbaabaabbaaabbababaaaaabbbaabaaabbaabaabaaabaaabaababaabbbbbbbbabbbbbabbbaabababbaababbbbbabbbbaaabbaabaabaaabbabbaaabbaaababaabbbaabbbaaaabbababbabaababababaaaabbaaaabaabaaaababaaabababbbaaabababbb...
output:
1281
result:
ok single line: '1281'
Test #2:
score: 0
Accepted
time: 579ms
memory: 264240kb
input:
aaaabababbabbbbbabbbbbbbbbbbabbbbbabbbaaabbbbaababaabbbbbbbbbbbbbabaabbaaabaababaabaaabbabbbabbbabaabbaabaababbbbbbaaabbbbaaabaabbbabbbabbabaabbbbabbbaabaaaabbbbbabaaaabaabbabaaabbaabbabbaaabbabaaababbababababaabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaaababaababbbbba...
output:
1483
result:
ok single line: '1483'
Test #3:
score: 0
Accepted
time: 571ms
memory: 263904kb
input:
bbaaababbbabbbaabbbbbbababbbabbbbbbbbaabbbbbbbbbbaaabbbbbbbbbbbbbbbabbabbbabaababbbabbbbabbabbabbbbabbbbbbbbbaaababbaaabbbaabbabbbbbbbbbbbbbbbbbbbbabbbbbbababababbbbbbbbbabababaabbbbbbabbbbaabbababbaaababbbbabbbbabbbabbbbbabbbbbabbbbbbbbbbabbaabbbabababbbbaababbbababbbbabbabbaabbbbbbabbbbbababbbbaba...
output:
2310
result:
ok single line: '2310'
Test #4:
score: 0
Accepted
time: 550ms
memory: 263340kb
input:
abbbbbbbbababbbbbbbbbabbbbbbbbabbbabbbbbaaabbbbbabbbbababbbabbbbbbaabbabbbbbaabbbbabbabbbbbbbabbbbaaabbbbbbaabbbbbbbbbbbbbbbbbbbbbabbbabbbabbbbbbbabbbbbbbabbbabbbbbbbbabbbabbbbbbbbbbbbbbbbbaababbbbbbbbbbabbbbbbbbbbbbbababbbbbbbabbbbbbababbbabbbbbaabbbbbbbbbaabbabbbbaabbbabbbbbbbbbbbbbabbbbbbbbbbbbbb...
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 553ms
memory: 262688kb
input:
bbbabbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbabbbbabbabbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbabbbbbbabbabbbbbbaabbbabbbbbbbbbbbbbbbbabbbbbabbbabbbbbbbabbbababbabbbbba...
output:
3680
result:
ok single line: '3680'
Test #6:
score: 0
Accepted
time: 512ms
memory: 257728kb
input:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbb...
output:
2454
result:
ok single line: '2454'
Test #7:
score: 0
Accepted
time: 552ms
memory: 251380kb
input:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
2702
result:
ok single line: '2702'
Test #8:
score: 0
Accepted
time: 170ms
memory: 112116kb
input:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
2499
result:
ok single line: '2499'
Test #9:
score: 0
Accepted
time: 565ms
memory: 264432kb
input:
amahaaajakalaiacabararasafaxasagamajaqagaqaeauauayagasadazavaeagabaaajalajavalatauapacaearaeagafawaaapawadaiaaapalahanavazasayamaiafagabahaxanacaaagaoadasakayagawaiaharanamaraiaramazaoagajataoazasalavatafaoalacaqavanafatajawauayakaoaqawawayasatasazagafacayasasawaqayadasaiazaxamaaaragataxawazadalaxak...
output:
2475
result:
ok single line: '2475'
Test #10:
score: 0
Accepted
time: 525ms
memory: 264556kb
input:
afabagadaeaeacaeaeafagafagababaaagacabaaagadacafadabaaaaacadaaagafacagadaeacacacabadagadaaabafadafadadaeafaaagadafabaeaaafaeaeaaaeabaaabaaaeafagadaaaaacaeaaaaacabaeacadagafafacacabaeaaagagaeaaadagabadaaaaagafagaaabaaaaafacafacadaaagabaaafadagacaaafafadadadacadadaaacagabacaaabacaeadabacagaeagagafafag...
output:
2807
result:
ok single line: '2807'
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
bbabbbaaabbbabaaaabababbabbbbbabbbbbbbbbbbabbbbbabbbaaabbbbaababaabbbbbbbbbbbbbabaabbaaabaababaabaaabbabbbabbbabaabbaabaababbbbbbaaabbbbaaabaabbbabbbabbabaabbbbabbbaabaaaabbbbbabaaaabaabbabaaabbaabbabbaaabbabaaababbababababaabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaa...
output:
result:
Subtask #3:
score: 5
Accepted
Test #16:
score: 5
Accepted
time: 8ms
memory: 6600kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
493827
result:
ok single line: '493827'
Subtask #4:
score: 0
Runtime Error
Test #17:
score: 0
Runtime Error
input:
bbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbabaabaaabbabbaaababaaabaaaabababbbbbbbaabbaaabbabbbbbabbbaaaaababbbaaabaabababbabbabababbabbabaaaaabaaaaaabbbabaabbbaaaabbabababaaababaabbbbbbbaaabbbabaabaaaabaabaababbaaaabababaabbbaaaababaaababbbbbbabbbbbbaabbabbaaa...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%