QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#860062 | #9970. Looping RPS | Fiyuls | WA | 1ms | 16400kb | C++14 | 1.4kb | 2025-01-18 09:59:05 | 2025-01-18 09:59:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5,maxCnt=2e6+5;
int n,tot=1,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]);
}
}
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;
u=son[u][c];
pos[i]=u;
}
for(int i=1;i<=n;i++){
rep[pos[i]]=max(rep[pos[i]],pos[las[i]]);
}
if(rep[u]){
u=rep[u];
}
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];
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: 16400kb
input:
6 P PN KK N PKK PN
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 16268kb
input:
10 KKKNP KNKPPKNK KNKPP KNKPPKN KKKN NNKNNNKNNNKNNNKNNNKNNNKNNNKNNPN NNKN NPPN NNKNNNKNNNKNNNKNNNKNNNKNNNK KKKNN
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'