记录编号 570801 评测结果 AAAAAAAAAA
题目名称 [NOI Online 2020 3rd PJ]紧急救助(民间数据) 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-04-18 22:37:08 内存使用 0.00 MiB
显示代码纯文本
#include <bits/stdc++.h>

using ull = unsigned long long;

const ull P = 13331, SOS = 3376795643;
int n;
std::string pep[110];
char s[110][210];
ull h[110][210], p[210];
std::map<int, std::vector<int>> mp;

ull get(int l, int r, int x) {
    return h[x][r] - h[x][l - 1] * p[r - l + 1];
}

int main() {
    freopen("noi_online2020_save.in", "r", stdin);
    freopen("noi_online2020_save.out", "w", stdout);
    std::cin >> n;
    for (int i = 1; i <= n; ++ i) std::cin >> pep[i] >> s[i] + 1;
    p[0] = 1;
    for (int i = 1; i <= n; ++ i) {
        int len = strlen(s[i] + 1);
        for (int j = 1; j <= len; ++ j) {
            h[i][j] = h[i][j - 1] * P + (s[i][j] - 'a' + 1);
            p[j] = p[j-1] * P;
        }
    }
    int mx = 0;
    for (int i = 1; i <= n; ++ i) {
        int cnt = 0;
        int len = strlen(s[i] + 1);
        for (int j = 1; j <= len - 2; ++ j)
            if (get(j, j + 2, i) == SOS) ++ cnt;
        mp[cnt].emplace_back(i);
        mx = std::max(mx, cnt);
    }
    for (auto i : mp[mx]) 
        std::cout << pep[i] << ' ';
    std::cout << '\n' << mx;
    return 0;
}