QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275643#5311. Master of Bothchitoge#TL 28ms84192kbC++231.3kb2023-12-04 22:00:362023-12-04 22:00:37

Judging History

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

  • [2023-12-04 22:00:37]
  • 评测
  • 测评结果:TL
  • 用时:28ms
  • 内存:84192kb
  • [2023-12-04 22:00:36]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")


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

vector<pair<int,int>> pex[1000001];

#define endl '\n'

int rex[27][27];

// set<pair<int,int> > vis;
unordered_set<int> vis[1000001];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,q;cin>>n>>q;
    string s;
    int maxlen=0;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=0;j<s.size();j++){
            pex[j].push_back(make_pair(s[j]-'a',i));
        }
        maxlen=max(maxlen,(int)s.size());
    }

    for(int i=0;i<maxlen;i++){
        for(int j=1;j<pex[i].size();j++){
            for(int k=0;k<j;k++){
                if(vis[pex[i][j].second].count(pex[i][k].second)||pex[i][j].first==pex[i][k].first)continue;
                    rex[pex[i][j].first][pex[i][k].first]++;
                    vis[pex[i][j].second].insert(pex[i][k].second);
                
            }
        }
    }

    for(int i=0;i<q;i++){
        string s;
        cin>>s;
        long long ans=0;
        for(int l=0;l<26;l++){
            for(int r=l+1;r<26;r++){
                ans+=rex[s[l]-'a'][s[r]-'a'];
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 81644kb

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

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
Time Limit Exceeded

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:


result: