QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#843267#9970. Looping RPSucup-team3474#ML 215ms981132kbC++201004b2025-01-04 17:43:072025-01-04 17:43:11

Judging History

你现在查看的是最新测评结果

  • [2025-01-04 17:43:11]
  • 评测
  • 测评结果:ML
  • 用时:215ms
  • 内存:981132kb
  • [2025-01-04 17:43:07]
  • 提交

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;
ll cnt[N];


void insert(string &s){
    int p=0;
    int len=60000000/(1ll*n*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;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        insert(s);
    }
    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

詳細信息

Test #1:

score: 100
Accepted
time: 215ms
memory: 981132kb

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

result: