QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629215#5311. Master of Bothclouds_WA 60ms52032kbC++231.8kb2024-10-11 09:11:522024-10-11 09:11:53

Judging History

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

  • [2024-10-11 09:11:53]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:52032kb
  • [2024-10-11 09:11:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define lowbit(x) x & (-x)
typedef pair<int, int> pii;
#define LF(x) fixed << setprecision(x)
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int N = 2e6 + 10, M = 1010, inf = 0x3f3f3f3f, mod = 1e9 + 7, P = 13331;

int son[N][30];
int cnt[N];
int idx;
int f[30][30];
int sum;

void insert(string s)
{
    int p=0;
    for(int i=0;i<s.size();i++)
    {
        int u=s[i]-'a';
        for(int j=0;j<26;j++)
        {
            if(son[p][j]&&u!=j)
            {
                f[u][j]+=cnt[son[p][j]];
            }
        }
        if(!son[p][u])
            son[p][u]=++idx;
        p=son[p][u];
        if(i==s.size()-1)
            sum+=cnt[p];
        cnt[p]++;
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        insert(s);
    }
//    cout<<sum<<endl;
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<26;j++)
        {
            char u=char(i+'a');
            char v=char(j+'a');
//            cout<<u<<" "<<v<<": "<<f[i][j]<<endl;
        }
    }
    while(m--)
    {
        string s;
        cin>>s;
        int ans=0;
        for(int i=0;i<s.size();i++)
        {
            int q=s[i]-'a';
            for(int j=i+1;j<s.size();j++)
            {
                int h=s[j]-'a';
                ans+=f[q][h];
            }
        }
        cout<<ans+sum<<endl;
    }
}
signed main()
{
    ios;
    int T;
    T = 1;
    // cin >> T;
    for (int cases = 1; cases <= T; ++cases)
    {
        // cout<<"Case #"<<cases<<": ";
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg

output:

4
3
4

result:

ok 3 number(s): "4 3 4"

Test #2:

score: 0
Accepted
time: 16ms
memory: 52032kb

input:

100 100
spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...

output:

2368
2693
2179
2466
2435
2370
2604
2468
2335
2268
2686
2781
2538
2208
2386
2539
2728
2383
2248
2372
2446
2266
2290
2688
2602
2515
2634
2558
2598
2632
2763
2255
2557
2579
2367
2516
2676
2273
2429
2556
2576
2635
2422
2829
2362
2552
2377
2261
2603
2516
2298
2282
2520
2333
2505
2287
2261
2476
2791
2328
...

result:

ok 100 numbers

Test #3:

score: -100
Wrong Answer
time: 60ms
memory: 37144kb

input:

500000 5
ru
x
tb
s
e
w
e
m
l
b
g
zr
jp
h
js
xk
fjwtk
wtkem
o
ev
a
a
x
sy
dh
y
kkdcxfr
hgq
j
k
xr
s
cvwbrlk
u
u
x
wtvgef
dzxsk
qv
gxl
g
m
rpl
ldp
q
lc
dk
g
k
im
o
yhn
z
a
knc
tyv
mz
ak
qdhq
c
niw
o
j
heu
w
g
e
kt
n
inqt
i
al
q
ebphky
sv
m
mry
oj
cl
j
r
sf
vpd
u
rio
sfkg
m
el
s
zs
g
o
e
njp
r
xczcm
gh...

output:

63118682346
63150734902
63093162384
63161330002
63134724416

result:

wrong answer 1st numbers differ - expected: '61908555824', found: '63118682346'