我的 ABC E 有什么过的理由吗?
  • 板块学术版
  • 楼主rainygame
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/5/11 22:11
  • 上次更新2024/5/11 22:16:16
查看原帖
我的 ABC E 有什么过的理由吗?
804607
rainygame楼主2024/5/11 22:11
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 300001
const int BASE(1e8+7);

int n, ans;
string s[MAXN];
vector<unsigned int> ha[MAXN];
unordered_map<unsigned int, int> tms;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i(1); i<=n; ++i){
        cin >> s[i];
        for (int j(0), now(0); j<s[i].size(); ++j){
            ha[i].push_back(now=now*BASE+(j+1)*(j+1)*s[i][j]);
            ++tms[now];
        }
    }

    for (int i(1); i<n; ++i){
        for (int j(0); j<s[i].size(); ++j) ans += --tms[ha[i][j]];
        // cout << '\n';
    }
    cout << ans;

    return 0;
}

你会发现我的 now 是 long long 的,也就是说我写了一个有符号整型溢出哈希。

2024/5/11 22:11
加载中...