QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625305#5311. Master of BothadivseWA 42ms54556kbC++202.0kb2024-10-09 18:30:172024-10-09 18:30:17

Judging History

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

  • [2024-10-09 18:30:17]
  • 评测
  • 测评结果:WA
  • 用时:42ms
  • 内存:54556kb
  • [2024-10-09 18:30:17]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename... Args>
void bubu(Args... args) { cout << ":: "; ((cout << args << " "), ...); cout << endl; }
void bubu(vector<int> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
using PII = pair<int, int>;
using i128 = __int128;

//=======================================================================
const int N = 1e6 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
int mp[30][30];// qianmian dayu houmian
//=======================================================================


int val[N];
int F[N][30];
int cnt;
int fan(char x) {
    return x - 'a';
}
void add(string& s) {
    int now = 0;
    // val[0]++;

    for (auto x : s) {
        if (!F[now][fan(x)]) F[now][fan(x)] = ++cnt;

        rep(i, 0, 25) {
            if (i == fan(x)) continue;
            //mp[i][fan(x)] += 1;
            if (F[now][i]) mp[i][fan(x)] += val[F[now][i]];
        }

        now = F[now][fan(x)];
        val[now]++;

    }
}

signed main() {
    kuaidu();
    int q; cin >> n >> q;
    rep(i, 1, n) {
        string s; cin >> s;
        add(s);
    }

    // int tem = 0;
    // rep(i, 0, 25) rep(j, 0, 25) {
    //     if (mp[i][j]) cout << char(i + 'a') << " " << char(j + 'a') << " " << mp[i][j] << endl;
    // }
    // cout << tem << endl;

    rep(i, 1, q) {
        string s; cin >> s;
        int ans = 0;
        rep(j, 0, 25) rep(p, j + 1, 25) {
            ans += mp[fan(s[p])][fan(s[j])];
        }
        cout << ans << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5584kb

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

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

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'