QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666451#5311. Master of BothtselmegkhWA 78ms47360kbC++201.6kb2024-10-22 18:33:132024-10-22 18:33:19

Judging History

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

  • [2024-10-22 18:33:19]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:47360kb
  • [2024-10-22 18:33:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
const int K = 26;

struct Vertex {
    int next[K];
    int lst = 0;

    Vertex() {
        fill(begin(next), end(next), -1);
    }
};

vector<Vertex> t(1);
int cnt[K][K];
long long ans;

void add_string(string const& s){
    int v = 0;
    bool isPrefix = true;
    for(char ch : s){
        int c = ch - 'a';
        for(int j = 0; j < 26; j++){
            if(t[v].next[j] != -1){
                cnt[j][c] += t[t[v].next[j]].lst;
            }
        }
        if(t[v].next[c] == -1){
            isPrefix = false;
            t[v].next[c] = t.size();
            t.emplace_back();
        }
        t[v].lst++;
        v = t[v].next[c];
    }
    ans += t[v].lst;
    t[v].lst++;
}

void solve(){
    int n, q;
    cin >> n >> q;

    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
        add_string(s[i]);
    }
    while(q--){
        string alphabet;
        cin >> alphabet;
        vector<int> pos(26, 0);

        for(int j = 0; j < 26; j++){
            pos[alphabet[j] - 'a'] = j;
        }
        long long res = 0;
        for(int i = 0; i < 26; i++){
            for(int j = 0; j < 26; j++){
                if(i == j)continue;
                if(pos[i] < pos[j]){
                    res += cnt[j][i];
                }
            }
        }
        if(n < 500000)cout << res + ans << '\n';
        else cout << res << '\n';
    }
    
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }        
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 7ms
memory: 31588kb

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: 78ms
memory: 47360kb

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:

60698136185
60730188741
60672616223
60740783841
60714178255

result:

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