QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#700210#5311. Master of BothHe_ng#RE 0ms3856kbC++201.4kb2024-11-02 12:22:102024-11-02 12:22:10

Judging History

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

  • [2024-11-02 12:22:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3856kb
  • [2024-11-02 12:22:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int N = 1e6;
const int M = 2e3;
int pr[26][26]; // 因为前i后j而产生差异的字符串数量
struct Trie {
    Trie(int n) : son(n * 50), cnt(n * 50), nidx(0) {}
    void insert(const vector<string> &vs) {
        for (int k = 0; k < vs.size(); k++) {
            int p = 0;
            for (int i = 0; i < vs[k].size(); i++) {
                int u = vs[k][i] - 'a';
                if (!son[p][u]) {
                    son[p][u] = ++nidx;
                }
                for (int j = 0; j < 26; j++) {
                    if (j == u)
                        continue;
                    pr[j][u] += cnt[son[p][j]];
                }
                cnt[son[p][u]] += 1;
                p = son[p][u];
            }
        }
    }

    int nidx;
    vector<array<int, 26>> son;
    vector<int> cnt;
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<string> vs(n);
    Trie tr(n);
    for (int i = 0; i < n; i++) {
        cin >> vs[i];
    }
    tr.insert(vs);
    string pp;
    while (q--) {
        cin >> pp;
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            for (int j = i + 1; j < 26; j++) {
                ans += pr[pp[j] - 'a'][pp[i] - 'a'];
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

詳細信息

Test #1:

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

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: -100
Runtime Error

input:

100 100
spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...

output:


result: