QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#540490 | #8339. Rooted Tree | OldMemory | WA | 1ms | 4004kb | C++14 | 2.7kb | 2024-08-31 17:09:32 | 2024-08-31 17:09:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> PII;
typedef long long LL;
const int INF = 0x3f3f3f3f3f3f3f3f;
bool multi = 0;
constexpr LL B = 1413214, P = 1e18 + 9;
struct strHash{
int n;
vector<LL> hz,pz;
strHash() {}
strHash(int n_, string &str) {
init(n_, str);
}
constexpr LL mul(LL a, LL b, LL p = P) {
LL res = a * b - LL(1.L * a * b / p) * p;
res %= p;
if (res < 0) {
res += p;
}
return res;
}
void init(int n_ ,string &str) {
n = n_;
hz.resize(n + 2);
pz.resize(n + 2);
pz[0] = 1;
for(int i = 1; i <= n; i++) {
hz[i] = (mul(hz[i-1], B) + str[i]) % P;
pz[i] = mul(pz[i-1], B);
}
}
LL findz(int l,int r){
return ((hz[r]-hz[l-1]*pz[r-l+1])%P+P)%P;
}
};
constexpr int len = sqrt(6000);
void solve(){
int n, q, m, k;
cin >> n >> q >> m >> k;
vector<string> s(n + 1);
vector<strHash> hs(n + 1);
for(int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = ' ' + s[i];
hs[i].init(m, s[i]);
}
vector<int> lb, rb;
int curl = 1;
while(curl <= m) {
int curr = min(m, curl + len - 1);
lb.push_back(curl);
rb.push_back(curr);
curl = curr + 1;
}
int tot = lb.size();
vector<vector<int>> bhs(n + 1, vector<int>(lb.size()));
for(int i = 1; i <= n; i++) {
for(int j = 0; j < tot; j++) {
bhs[i][j] = hs[i].findz(lb[j], rb[j]);
}
}
while(q--) {
string t;
cin >> t;
t = ' ' + t;
strHash ht(m, t);
vector<int> ths(lb.size());
for(int i = 0; i < lb.size(); i++) {
ths[i] = ht.findz(lb[i], rb[i]);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
int curk = k;
bool ok = 1;
for(int j = 0; j < tot; j++) {
if(ths[j] != bhs[i][j]) {
for(int p = lb[j]; p <= rb[j]; p++) {
if(t[p] != s[i][p]) {
curk--;
if(curk < 0) {
j = tot;
ok = 0;
break;
}
}
}
}
}
if(ok) {
ans++;
}
}
cout << ans << '\n';
}
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
if(multi) cin >> T;
while(T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4004kb
input:
6 2
output:
6 6
result:
wrong answer 1st numbers differ - expected: '18', found: '6'