题意

定义函数f(s,t)f(s, t)表示sstt中出现的次数,然后让你对每个字符串ii, 求解0jnf(si,sj)\prod_{0 \leq j \leq n} f(s_i, s_j)

思路

长度超过最短长度的肯定为00,或者如果最短长度的字符串不全部相等的话也为00

根据这个发现,我们就可以只求最短那个串的答案即可

易错点

一开始看错题目了,累乘以为是累加

代码

/**
 *    author: andif
 *    created: 22.06.2023 18:16:51
**/
#include<bits/stdc++.h>
using namespace std;

#define de(x) cerr << #x << " = " << x << endl
#define dd(x) cerr << #x << " = " << x << " "
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define per(i, a, b) for(int i = a; i > b; --i)
#define mt(a, b) memset(a, b, sizeof(a))
#define sz(a) (int)a.size()
#define fi first
#define se second
#define qc ios_base::sync_with_stdio(0);cin.tie(0)
#define eb emplace_back
#define all(a) a.begin(), a.end()
using ll = long long;
using db = double;
using pii = pair<int, int>;
using pdd = pair<db, db>;
using pll = pair<ll, ll>;
using vi = vector<int>;
const db eps = 1e-9;
const int mod = 998244353;

vi get_next(const string& s) {
    int n = sz(s) - 1;
    vi next(n + 1, 0);
    rep(i, 2, n + 1) {
        int j = i - 1;
        while(j && s[i] != s[next[j] + 1]) j = next[j];
        if (j) next[i] = next[j] + 1;
    }
    return next;
}

int match(const string& s, const string& p, const vi& next) {
    int ret = 0;
    int n = sz(s) - 1, m = sz(p) - 1;
    int i = 1, j = 1;
    while(i <= n) {
        if (s[i] == p[j]) {
            if (j == m) {
                ret++;
                j = next[j];
            }
            i++; j++;
        } else if (j == 1) {
            i++;
        } else {
            j = next[j - 1] + 1;
        }
    }
    return ret;
}

int main() {
    qc;
    int n; cin >> n;
    vector<string> s(n);
    int mn = numeric_limits<int>::max();
    int golden = -1;
    rep(i, 0, n) {
        cin >> s[i];
        s[i] = '#' + s[i];
        if (mn > sz(s[i])) {
            mn = sz(s[i]);
            golden = i;
        }
    }
    vi next = get_next(s[golden]);
    int golden_ans = 1;
    rep(i, 0, n) {
        golden_ans = 1ll * golden_ans * match(s[i], s[golden], next) % mod;
    }
    rep(i, 0, n) {
        if (sz(s[i]) > mn) {
            cout << '0' << '\n';
        } else {
            cout << golden_ans << '\n';
        }
    }
    return 0;
}