QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#860246 | #9970. Looping RPS | Fiyuls | WA | 2ms | 17020kb | C++14 | 1.8kb | 2025-01-18 11:34:10 | 2025-01-18 11:34:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5,maxCnt=4e6+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++){
if(deep[rep[pos[i]]]<deep[pos[las[i]]])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];
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: 0ms
memory: 16904kb
input:
6 P PN KK N PKK PN
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 16748kb
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: 15928kb
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: 0ms
memory: 17020kb
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: 15840kb
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: 16456kb
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: 15832kb
input:
4 KKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPK NN KKP KKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKNK
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 15716kb
input:
7 KPKN KPKNKPKNKPKNKPKK NKPPNNNPKKNN KPPKPKPPKPKPPKPKPPKPKPP KPKNKPKNKPKNKP KPPKP KPPKPKPPKPKPPKPKPPKPKPPKPN
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 0ms
memory: 15484kb
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: 16776kb
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: 2ms
memory: 15136kb
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: 15856kb
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: -100
Wrong Answer
time: 0ms
memory: 16712kb
input:
91 PKKK KKKNKKKKNKKKKNKK PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPKP PPPPNPPPPNPPPPNPPPPNPPPPK PPPPNNPPPPPNNPPPPPNNPPPPPNNPPPPK NKNKNKNKN PNPPNPKPPNPPN NPKNPKNPKNPKNPKNPKNPKNPKNP PNPPNPKPPNP KKPK KKKKKNKKKKKKNKKKKKPN NPK PPNKPPKPPNKPPPNKPPK KKP PNPPNPPNPPNPKK PPPPPPNPPPPPPNPPPPPPNPPPPPPK PPPPPPNPPP...
output:
24735
result:
wrong answer 1st numbers differ - expected: '24738', found: '24735'