1 条题解
-
0
#include <bits/stdc++.h> #define ll long long using namespace std; int n, m; // hash const ll MOD1 = 1000000007, MOD2 = 998244353; const ll P1 = 29, P2 = 31; pair<ll, ll> getHash(const string &s) { ll hash1 = 0; ll hash2 = 0; for (int i = 0; i < s.length(); i++) { hash1 = (hash1 * P1 + s[i] - 'a' + 1) % MOD1; hash2 = (hash2 * P2 + s[i] - 'a' + 1) % MOD2; } return make_pair(hash1, hash2); } set<pair<ll, ll>> se[1005]; string tempS; pair<ll, ll> pll; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int k; cin >> k; while (k--) { cin >> tempS; se[i].insert(getHash(tempS)); } } cin >> m; while (m--) { cin >> tempS; pll = getHash(tempS); for (int i = 1; i <= n; i++) if (se[i].find(pll) != se[i].end()) cout << i << " "; cout << "\n"; } return 0; }
- 1
信息
- ID
- 1356
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 2
- 标签
- 递交数
- 44
- 已通过
- 8
- 上传者