QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378703 | #8571. Palworld | ucup_team_qiuly# | RE | 1026ms | 39432kb | C++17 | 1.8kb | 2024-04-06 14:16:40 | 2024-04-06 14:16:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define lg(x) (31^__builtin_clz(x))
const int N=4e5+5;
int T,n,m,up,tp,ans,a[N],o[N],bc[N],sa[N],rk[N],mn[19][N];char a1[N];
void rSort()
{
fill(bc,bc+up+1,0);for(int i=1;i<=n;++i) ++bc[rk[o[i]]];
partial_sum(bc,bc+up+1,bc);for(int i=n;i;--i) sa[bc[rk[o[i]]]--]=o[i];
}
void build()
{
up=300;copy(a+1,a+n+1,rk+1);iota(o+1,o+n+1,1);rSort();
for(int l=1,t;l<=n;l*=2)
{
tp=0;for(int i=1;i<=l;++i) o[++tp]=n-i+1;
for(int i=1;i<=n;++i) if(sa[i]>l) o[++tp]=sa[i]-l;
rSort();for(int i=1;i<=n;++i) swap(rk[i],o[i]);t=rk[sa[1]]=1;
for(int i=2;i<=n;++i)
rk[sa[i]]=(o[sa[i]]==o[sa[i-1]] && o[sa[i]+l]==o[sa[i-1]+l])?t:++t;
if(t==n) break;up=t;
}
for(int i=1,j,t=0;i<=n;++i) if(rk[i]>1)
{
j=sa[rk[i]-1];if(t) --t;
while(i+t<=n && j+t<=n && a[i+t]==a[j+t]) ++t;mn[0][rk[i]]=t;
}
for(int i=1;(1<<i)<=n;++i) for(int j=1;j+(1<<i)-1<=n;++j)
mn[i][j]=min(mn[i-1][j],mn[i-1][j+(1<<i-1)]);
}
int qry(int x,int y)
{
if(x<1 || y>n) return 0;int t1=n-y+1;
x=rk[n*2-x+1];y=rk[y];if(x>y) swap(x,y);++x;
int t=lg(y-x+1);return min({mn[t][x],mn[t][y-(1<<t)+1],t1});
}
void slv()
{
scanf("%d %d %s",&n,&m,a1+1);ans=0;
for(int i=1;i<=n;++i) a[i]=a1[i],a[n+i]=a1[n-i+1];
n*=2;build();n/=2;
for(int i=1;i<=n;++i) for(int j=0;j<=m;++j)
if(i+j-1<=n) ans=max(ans,j+m+qry(i-1,i+j)*2);
for(int i=1,t;i<=n;++i)
{
t=qry(i,i);
for(int j=0;j<=m;++j)
{
if(i+j+t-1<=n) ans=max(ans,(j+t+qry(i-t,i+j+t))*2-1);
if(i-j-t+1>0) ans=max(ans,(j+t+qry(i-j-t,i+t))*2-1);
}
}
for(int i=1,t;i<n;++i)
{
t=qry(i,i+1);
for(int j=0;j<=m;++j)
{
if(i+j+t<=n) ans=max(ans,(j+t+qry(i-t,i+j+t+1))*2);
if(i-j-t+1>0) ans=max(ans,(j+t+qry(i-j-t,i+t+1))*2);
}
}printf("%d\n",ans);
}
int main()
{
scanf("%d",&T);
while(T--) slv();return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
input:
4 1 3 a 4 1 icpc 4 2 icpc 8 4 icecream
output:
4 5 5 11
result:
ok 4 number(s): "4 5 5 11"
Test #2:
score: 0
Accepted
time: 650ms
memory: 39432kb
input:
1 200000 66 jsmwjmibgkjvdscqllsxpaxiycmpauhnzschbivtqbjfrxrqvhvfbqecozjewqqpwdfbeqppjkgxhbnniopkptkygspcdswhwadfwhnzovvpshgcdukrupeztkpxwhmctaquqbxtidzbbxsyuaeikuldaoeudletrsmqptaejibkymsjhmwykqsjdvvdaqwelrcpxwrwhuvodipjniowfofbjktkdezwqqbvwsppsmpilntmdmlxgkaxymnugmmcsljkjzjuudnllydwdwwanadynsoiolso...
output:
141
result:
ok 1 number(s): "141"
Test #3:
score: 0
Accepted
time: 1026ms
memory: 39072kb
input:
1 200000 100 qhiaajzxinenucrnfffumuhnovpuwcnojbhsktztapgyivmfqrlntwazwnfetwqieckxcnkskpidltiydfoveaucckximydxxfbiwbdufmbhywqkflyqxbijakadqkzftlciccbpnldsqhtjxuxnvkusvizavuyfhdroiuominebadhfqzrpjnzpgyvkejfwmueiltyeqpvwrkanqknyacqganbszktocfuvvsfrboaennwpaabfdnaurvvurysrijnfaonesihbhrrvbvyhpbremsuhhbc...
output:
209
result:
ok 1 number(s): "209"
Test #4:
score: 0
Accepted
time: 66ms
memory: 3864kb
input:
10000 21 7 fhcjhdjcfbfbdeeheibhg 18 8 hccgjfaadefhjhcijc 15 7 ahefiiheaigjiid 15 3 fgjjebidbfgbdij 15 5 jccebbgjbhifjhb 20 2 hcbddhibgfccjjcfebcc 19 1 ehbdgiicchijebidbcd 20 8 gbcfghefhbjggecdhcbj 17 2 jjaeaccjbcfiehfdd 23 4 iafjedfbebbhcfgfjbehdaf 22 1 jgiiiaacehcbaiehfggcfi 17 2 jefbbfigfhbhfcici ...
output:
17 21 17 11 13 9 6 18 9 11 6 9 22 8 21 23 5 23 7 16 9 23 25 11 17 12 9 5 20 5 23 12 7 13 16 17 21 21 21 12 16 21 21 8 9 11 21 15 5 24 13 7 21 13 11 8 7 19 25 7 8 12 13 22 15 14 7 15 7 20 15 13 11 15 5 11 23 17 17 19 15 7 19 17 25 13 23 10 17 21 9 21 7 23 21 13 16 7 14 10 13 10 9 11 7 21 15 19 11 23 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 202ms
memory: 39032kb
input:
1 200000 100 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
200100
result:
ok 1 number(s): "200100"
Test #6:
score: 0
Accepted
time: 851ms
memory: 39256kb
input:
1 200000 73 jgqahsycxmrrwvszqigkxmxxckratkgiyyqbxgjzaqkufvkgmepixhjdugpsntlsgtiedueukiytrytrcvlkymwibsfdhytbffmtaytnfczbavrrbdnpegwxubyeoopzopqhrwukohojtaizsureefffglwjfawvpqqnjteveuscyelgjiukskvymqejzwlnrjgvnpwnttzahoupruedryqeyahxgltnibxhbpxmhxxnmrebsgbjwsfpipezkekaqptnwtuanbfyfwyotwkrvlamnuvhunty...
output:
175682
result:
ok 1 number(s): "175682"
Test #7:
score: -100
Runtime Error
input:
10000 12 1 jelwdrimpvtq 19 8 qcogumialfqhaahfhtb 11 12 tbnfsiqbibv 5 4 hdehb 4 1 ivxi 7 8 nonrwqa 14 16 obvpfqjekvmnyq 4 5 fzhi 18 17 gploorpjnrrhcrgxlp 2 3 pf 7 9 uiliuyr 1 3 v 3 3 bgj 9 4 tektrwtmk 10 4 vvkvbzpbye 20 5 jqzqpqiwkssksbilayvj 2 4 kl 5 2 vptsk 20 9 kuiwsxhfmirnrhzuysqd 8 8 aairrgjl 15...