QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#860195 | #9970. Looping RPS | Fiyuls | RE | 2ms | 17248kb | C++14 | 1.8kb | 2025-01-18 11:07:35 | 2025-01-18 11:07:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5,maxCnt=8e6+5;
int n,tot=1,deep[maxn],Size[maxCnt],son[maxCnt][3],rep[maxCnt];
long long ans;
string s[maxn];
void Ins(string s){
static int Next[maxCnt],las[maxCnt],pos[maxCnt],n;
n=s.length()-1;
for(int i=0;i<=n;i++){
Next[i]=las[i]=0;
}
for(int i=1,j=(Next[0]=-1);i<=n;i++){
while(~j and s[i]!=s[j+1]){
j=Next[j];
}
Next[i]=++j;
if(Next[i]*2>=i)las[i-Next[i]]=i;
}
for(int i=n;i>=1;i--){
for(int j=i+i;j<=n;j+=i){
las[j]=max(las[j],las[i]);
}
}
for(int i=1;i<=n;i++)if(las[i]<=i)las[i]=0;
int u=1;
for(int i=1;i<=n;i++){
int c=(s[i]=='N'?0:(s[i]=='K'?1:2));
if(!son[u][c])son[u][c]=++tot,deep[tot]=deep[u]+1;
u=son[u][c];
pos[i]=u;
}
for(int i=1;i<=n;i++){
rep[pos[i]]=max(rep[pos[i]],pos[las[i]]);
}
int head=1;
if(rep[u]){
head=(deep[rep[u]]-deep[u])%n+1,u=rep[u];
}
for(int i=head;i<=n;i++){
int c=(s[i]=='N'?0:(s[i]=='K'?1:2));
if(!son[u][c])son[u][c]=++tot;
u=son[u][c];
pos[i]=u;
}
for(int i=head;i<=n;i++){
rep[pos[i]]=max(rep[pos[i]],pos[las[i]]);
}
Size[u]++;
}
void DFS(int u){
if(!u){
return;
}
long long res=1;
for(int i=0;i<=2;i++){
DFS(son[u][i]),Size[u]+=Size[son[u][i]],res=res*Size[son[u][i]];
}
ans+=res;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>s[i],s[i]='>'+s[i]+s[i]+s[i]+s[i];
sort(s+1,s+1+n,[](string a,string b){return a.size()>b.size();});
for(int i=1;i<=n;i++){
Ins(s[i]);
}
DFS(1);
cout<<ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 17024kb
input:
6 P PN KK N PKK PN
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 17176kb
input:
10 KKKNP KNKPPKNK KNKPP KNKPPKN KKKN NNKNNNKNNNKNNNKNNNKNNNKNNNKNNPN NNKN NPPN NNKNNNKNNNKNNNKNNNKNNNKNNNK KKKNN
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 15644kb
input:
10 NNNPNNNPNNNPNNNK KKN NNNP KKP NNNPNNNPNNNPN KKNKKNKKPN KNNPNPNKKKNPPKNKKKNKNKKNKPPPNKKPKP KKPK KKNKKNK KKPKKN
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 1ms
memory: 15660kb
input:
10 K PPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNP PPKP PPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPK P K N P PPPNN N
output:
25
result:
ok 1 number(s): "25"
Test #5:
score: 0
Accepted
time: 0ms
memory: 16008kb
input:
10 NPNKP NNNNKNNNNPP PPKPNNNNPNKKKN NPNKPNP NNNNKN NNNNK NKNPKKPNPKKNPNKN NKNPKKPNPKKNPNK NKNPKKPNPKKNP NPNKPNPN
output:
30
result:
ok 1 number(s): "30"
Test #6:
score: 0
Accepted
time: 1ms
memory: 16808kb
input:
10 KPKKPKKPKKPKKP KPKKPKKPKKPKKPKNK PNPNP KPK PN NPNPNNPNPNK NKKPKKPKPPKKPKKKKPKNKPPKPPNKNP NPNPNNP PNPNPK NPNPN
output:
39
result:
ok 1 number(s): "39"
Test #7:
score: 0
Accepted
time: 0ms
memory: 15320kb
input:
4 KKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPK NN KKP KKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKNK
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 16044kb
input:
7 KPKN KPKNKPKNKPKNKPKK NKPPNNNPKKNN KPPKPKPPKPKPPKPKPPKPKPP KPKNKPKNKPKNKP KPPKP KPPKPKPPKPKPPKPKPPKPKPPKPN
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 1ms
memory: 16676kb
input:
10 NKNNKNKN KPKN PKPN PNNNNNNKKNNPNNKNPPKPPNPNPPKKKPNNNPNPKKNK PKPNPKP PKPNPK KPKNKP NKNNKNKNNKNPN KPKNKPK NKNNK
output:
39
result:
ok 1 number(s): "39"
Test #10:
score: 0
Accepted
time: 0ms
memory: 16148kb
input:
300 NKNPNK NKKNKK KPPNPN KKPNKNK PKKNPKP KPKPPPN NNKPPNN NPKPPKN KNNKKPK PPPNPKK NKPKNP KPKNNPP NNPKNP PNPPPKN PKKPNP PPNNKK PKNKNK PKNPNK NKNPNPP KNKNNPN NKPPPPK NNPPKKN KNKKNPK KKNNPKN PPPKNK NPPPPPP NKKPKPP KNKNPPK KPKPNNK NPNNKN PNPNKP PNPKKP KKKKPKN NNNKNPK NPNKPNK NNNKNK PPKKNKP NNNKPPK KPNKPP...
output:
1102940
result:
ok 1 number(s): "1102940"
Test #11:
score: 0
Accepted
time: 1ms
memory: 17248kb
input:
91 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKN KKKKKKKKP PNPKPPNP KKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKP KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKP KKKKKKKKKKKKKKKKKKKKKKN KKKKKKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKP KKKKKKKKKKKKP ...
output:
2151
result:
ok 1 number(s): "2151"
Test #12:
score: 0
Accepted
time: 1ms
memory: 16260kb
input:
72 PKPPKPPKPPKPPKPPN PKP NNNNNK NPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNP NNPNNPNNPNNPNNPNNK NP PPPPPPN PKPPKPPKPPKPPKPP PPPPKPP PPK NNNNNPP NNNNPNNNNPNNNNPN KPNNNKKPPKPKKNPPKKNNKPKPKPKPPPKPPKPNNKPPKPPPNNNKKNNPKKKKKN...
output:
14794
result:
ok 1 number(s): "14794"
Test #13:
score: 0
Accepted
time: 2ms
memory: 16824kb
input:
91 PKKK KKKNKKKKNKKKKNKK PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPKP PPPPNPPPPNPPPPNPPPPNPPPPK PPPPNNPPPPPNNPPPPPNNPPPPPNNPPPPK NKNKNKNKN PNPPNPKPPNPPN NPKNPKNPKNPKNPKNPKNPKNPKNP PNPPNPKPPNP KKPK KKKKKNKKKKKKNKKKKKPN NPK PPNKPPKPPNKPPPNKPPK KKP PNPPNPPNPPNPKK PPPPPPNPPPPPPNPPPPPPNPPPPPPK PPPPPPNPPP...
output:
24738
result:
ok 1 number(s): "24738"
Test #14:
score: 0
Accepted
time: 1ms
memory: 16856kb
input:
130 PKPKPKPKPNPKPKPKPKPKPN NPNPNPNPN N PNKPNKP PNKPK NNNNKNNNNPPNNNNKNNNNNKNNNNPP NNNNNNNNKNNNNNNNNKN NK K NPPNKNPPN NKNKNKNNKNKNKNNKNKNKNNKNKNKNKNNKNKNKNNKNKNKNNKNKNKNPN PKPKPKPKPKPKPKPKPKPKPNKPKPKPKPKPKPKPKPKPKPKP NNNNNNNNK KKKN PPPN NNNNNNNNNNNNKN NPKNPKNPP PPPKNPPPKNPPPKNP PPPPPNP KKP PKN PPPPPN...
output:
86902
result:
ok 1 number(s): "86902"
Test #15:
score: 0
Accepted
time: 0ms
memory: 15704kb
input:
76 N NKNKNNKNKNKN KPKPKPKPKPKN NK KKKKKNK NNPNNPNNKNNPNNPNNNPNNPNNKNNPNNPNNKNNPNNPNNNPNNPNNKNNPNNPNNPNNKNNPNNPNNNPNNPNNKNNPNNPNNKNNPNNPNNNPNNPNNKNNPNNPNNPNNKNNPNNPNNNPNNPNNKNNPNNPNNKNNPNNPNNNPNNPNNKNNPNNPNNPNNKNNPNNPNNNPNNPNNK NNPNNPNNPNNPNNPNNPNNPNNPNNK KKKKKKKKKKPKKKKKKKKKKNP KKPKKPK PPPPPPPPPPPN ...
output:
12533
result:
ok 1 number(s): "12533"
Test #16:
score: 0
Accepted
time: 1ms
memory: 15580kb
input:
35 KPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKNKKP P KNKNKKNKNKNKKNKNKP N KKKKKKKKKKKKKKKKKKKKPKKKKKKKKKKKKKKKKKKKKKP PNPNPNP KPKPKPKPKPKPKPKPKNKKPKPKPKPKPKPKPKPKPKNK...
output:
1178
result:
ok 1 number(s): "1178"
Test #17:
score: 0
Accepted
time: 0ms
memory: 16112kb
input:
19 KPKPKPKPKKPKPKPKPKKPKPKPKPKKPKPKPKPKN NPNPNNPNPNNP NPNPNNPNPNNPNPNPNNPNPNNPNPNPNNPNPNNPNPNPNNPNPNNPNPNPNNPNPNNPNPNK NPNPNNPNPNNPNPNPNNPNPNNPNPNPNNPNPNNPNPNPNNPNPNNPNPNPN KPKNPKPKNPKPKKPKNPKPKNPKPKKPKNPKPKNPKPKKPKNPKPKNPKPKKPKNPKPKNPKPKKPKNP NKKKPNKPKNKPPPNKPPNPNNNNPKPKPNKKNPNKKPNPNPKNKPPKKNNKPPKK...
output:
249
result:
ok 1 number(s): "249"
Test #18:
score: 0
Accepted
time: 0ms
memory: 15700kb
input:
32 NNKPNNNKPNNP PNPPNPPNPPNPPNPK PNP NNPNNNPNNPNNNPNNPNNNPNNPN P NNPNNNPNNPNNNPNNPNNNPNNPNNNPNNK NKNKNKNP NNNNNNNNP NPKNKNPKNKNPKNKNPKNKNPK N N PPPPKP N KPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPKKPKPKPK...
output:
894
result:
ok 1 number(s): "894"
Test #19:
score: 0
Accepted
time: 1ms
memory: 15764kb
input:
300 PKK KNP PNPNPKPNPNPNPKPNPNPP KNN KPN KNN KKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNKKKNK KKKN ...
output:
1120793
result:
ok 1 number(s): "1120793"
Test #20:
score: -100
Runtime Error
input:
45 PPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPPPPPPPPPKPP...