strcmp
2024-11-18 15:20:01
多校联考原题。
给一个复杂度正确的类星战 Sum Hash 做法,
设
于是就是将所有
当然复杂度是错的,
发现对于某一个
注意到字符集很小,暴力枚举
然后你发现这个暴力枚举也没有什么必要,维护
时间复杂度
#include <bits/stdc++.h>
#define X first
#define Y second
#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 mp make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
using pii = pair<int, int>;
using ull = unsigned long long int;
constexpr ll inf = 1e11;
constexpr int maxn = 5e3 + 10, mx = 1e9, mod = 998244353;
mt19937_64 rd(114514);
char s[maxn][maxn]; int n, m, k;
inline int id(char c) { return c == 'A' ? 0 : c == 'T' ? 1 : c == 'G' ? 2 : c == 'C' ? 3 : 4; }
char t[6] = { 'A', 'T', 'G', 'C' };
ull w[maxn], g[maxn], sum, f[4][maxn];
int main() {
scanf("%d%d%d", &n, &m, &k);
rep(i, 1, n) scanf("%s", s[i] + 1), sum += (w[i] = rd());
rep(i, 1, n) rep(j, 1, m) f[id(s[i][j])][j] += w[i], g[j] += w[i];
rep(i, 1, n) {
ull d = 0;
rep(j, 1, m) d += g[j] - f[id(s[i][j])][j];
if ((sum - w[i]) * k == d) printf("%d\n", i), exit(0);
}
return 0;
}