QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#843326 | #9970. Looping RPS | ucup-team3474# | ML | 211ms | 970712kb | C++23 | 1.4kb | 2025-01-04 17:59:02 | 2025-01-04 17:59:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e8+10,mod=1e9+7;
ll n,m,k;
ll ny;
int tr[N][3];
int idx;
int totlen;
ll cnt[N];
string s[1000010];
void insert(string &s,int len){
int p=0;
// int len=55000000/s.size()+1;
for(int c=1;c<=len;c++){
for(int j=0;j<s.size();j++){
char ch=s[j];
int t;
if(ch=='P') t=0;
else if(ch=='N') t=1;
else t=2;
if(!tr[p][t]) tr[p][t]=++idx;
p=tr[p][t];
cnt[p]++;
}
}
}
void __(){
cin>>n;
// if(n<=1000)
for(int i=1;i<=n;i++){
// string s;
cin>>s[i];
totlen+=s[i].size();
// insert(s);
}
double res=0;
for(int i=1;i<=n;i++){
res+=1.0*totlen/s[i].size();
}
int mxlen=55000000;
for(int i=1;i<=n;i++){
double val=1.0*totlen/s[i].size()/res;
double len=val*mxlen;
int needlen=ceil(len/s[i].size())+1;
insert(s[i],needlen);
}
cnt[0]=0;
ll ans=0;
for(int i=0;i<=idx;i++){
ll res=cnt[tr[i][0]]*cnt[tr[i][1]]*cnt[tr[i][2]];
ans+=res;
}
cout<<ans<<endl;
}
int main()
{
int _=1;
// ny=mod/2+1;
// cin>>_;
while(_--){
__();
}
}
//51423
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 211ms
memory: 970712kb
input:
6 P PN KK N PKK PN
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: -100
Memory Limit Exceeded
input:
10 KKKNP KNKPPKNK KNKPP KNKPPKN KKKN NNKNNNKNNNKNNNKNNNKNNNKNNNKNNPN NNKN NPPN NNKNNNKNNNKNNNKNNNKNNNKNNNK KKKNN
output:
3