QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#652794#9406. TriangleUESTC_Snow_Halation#WA 2ms14000kbC++142.5kb2024-10-18 19:09:032024-10-18 19:09:08

Judging History

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

  • [2024-10-18 19:09:08]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:14000kb
  • [2024-10-18 19:09:03]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define FOR() ll le=e[u].size();for(ll i=0;i<le;i++)
#define QWQ cout<<"QwQ\n";
#define ll long long
#include <vector>
#include <queue>
#include <map>

using namespace std;
const ll N=801010;
const ll qwq=303030;
const ll inf=0x3f3f3f3f;

inline ll read() {
    ll sum = 0, ff = 1; char c = getchar();
    while(c<'0' || c>'9') { if(c=='-') ff = -1; c = getchar(); }
    while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
    return sum * ff;
}

ll T,n;
ll tot;
char s[N];
ll siz[N],siz2[N],siz3[N];
ll ans;
ll to[N][26];
ll xiao;
ll fa[N];
ll hou[27];

void calc(ll u,ll v) {
    hou[26] = 0;
    for(ll i=25;i>=0;i--) {
        hou[i] = hou[i+1];
        if(to[v][i]) hou[i] += siz2[to[v][i]];
    }
    for(ll i=0;i<26;i++) {
        ll xia = to[u][i];
        if(!xia) continue;
        ans += siz3[xia] * hou[i+1];
    }
    for(ll i=0;i<26;i++) {
        if(to[u][i] && to[v][i]) calc(to[u][i],to[v][i]);
    }
}

void DFS(ll u) {
    if(siz[u]) {
        if(siz[u]>=2) {
            ans += xiao * (siz[u]*(siz[u]-1)/2);
        }
        if(siz[u]>=3) {
            ans += siz[u]*(siz[u]-1)*(siz[u]-2)/6;
        }
        xiao += siz[u];
        while(siz[u]--) {
            // for(ll i=0;i<26;i++) if(to[u][i] && to[0][i]) calc(to[u][i],to[0][i]);
            calc(u,0);
            ll now = u;
            while(now) {
                siz2[now]++;
                now = fa[now];
            }
        }
    }
    for(ll i=0;i<26;i++) {
        if(to[u][i]) DFS(to[u][i]);
    }
}

void chushihua() {
    for(ll i=0;i<=tot;i++) {
        for(ll j=0;j<26;j++) to[i][j] = 0;
        siz[i] = siz2[i] = siz3[i] = fa[i] = 0;
    }
    xiao = 0;
    ans = 0;
    tot = 0;
}

int main() {
    T = read();
    while(T--) {
        chushihua();
        n = read();
        for(ll i=1;i<=n;i++) {
            ll now = 0;
            scanf("%s",s+1); ll le = strlen(s+1);
            for(ll j=1;j<=le;j++) {
                ll c = s[j] - 'a';
                if(!to[now][c]) to[now][c] = ++tot, fa[tot] = now;
                now = to[now][c];
            }
            siz[now]++;
            while(now) {
                siz3[now]++;
                now = fa[now];
            }
        }
        DFS(0);
        cout<<ans<<"\n";
    }
    return 0;
}

/*

1
6
cbaa
cb
cb
cbaa
ba
ba

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 14000kb

input:

3
6
cbaa
cb
cb
cbaa
ba
ba
3
sdcpc
sd
cpc
1
ccpc

output:

16
0
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 11996kb

input:

14
1
lfpbavjsm
2
pdtlkfwn
mbd
3
dvqksg
dvqksg
uhbhpyhj
4
ombwb
ombwb
ombwb
ombwb
5
oztclz
oztclz
oztclz
oztclz
kul
6
vco
vco
vco
dtktsqtinm
vco
vco
7
tb
tb
kowbsu
ygkfphcij
tb
uvei
tb
8
vxxtxssht
abnsxbf
bydaae
bydaae
udalyvmcef
bydaae
bydaae
bydaae
9
aaze
zvyonw
qjfv
mmhkef
qjfv
qjfv
qjfv
mmhkef
qj...

output:

0
0
0
4
10
20
10
20
41
14
63
74
18
11063

result:

wrong answer 14th lines differ - expected: '11081', found: '11063'