QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#658999 | #8339. Rooted Tree | the_foo# | WA | 0ms | 3624kb | C++20 | 3.2kb | 2024-10-19 18:09:48 | 2024-10-19 18:09:51 |
Judging History
answer
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int n,q,m,k;
constexpr int N = 6E4 + 10;
struct Hash {
int n;
vector<array<LL, 2>> v;
static constexpr array<LL, 2> mod = {998244353, 1000000007};
inline static array<array<LL, 2>, N> p;
static constexpr array<LL, 2> base = {131, 247};
Hash() = default;
Hash (int _n, string s) {
n = _n;
v.assign(n + 1, {});
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 2; j++) {
v[i][j] = (v[i - 1][j] * base[j]) % mod[j] + s[i];
while (v[i][j] >= mod[j]) v[i][j] -= mod[j];
}
}
}
array<LL, 2> get(int l, int r) {
array<LL, 2> res;
for (int j = 0; j < 2; j++) {
res[j] = v[r][j] - v[l - 1][j] * p[r - l + 1][j] % mod[j];
if (res[j] < 0) res[j] += mod[j];
}
return res;
}
static void initp() {
for (int j = 0; j < 2; j++) {
p[0][j] = 1;
for (int i = 1; i < N; i++) {
p[i][j] = p[i - 1][j] * base[j] % mod[j];
}
}
}
};
int L,R;
Hash hs[305];
Hash ht;
bool check(int i,int x)
{
if(hs[i].get(L,x)==ht.get(L,x))return 1;
else return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>q>>m>>k;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
hs[i] = Hash(m, ' ' + s);
}
while(q--) {
string t;
cin>>t;
ht = Hash(m, ' ' + t);
int ans=0;
for(int i=1;i<=n;i++)
{
L=1,R=m+1;
int cnt=0;
//bool f=1;
while(cnt<=k)
{
if(L>m)break;
//cout<<L<<' '<<R<<endl;
//cout<<cnt<<endl;
int l=L,r=R;
if(hs[i].get(l,l)!=ht.get(l,l)) {
//cnt+=n-l+1;
cnt++;
L++;
cout<<"<<"<<r<<endl;
continue;
}
while(l+1<r) {
int mid=(l+r)/2;
if(check(i,mid))l=mid;//r=mid-1;
else r=mid;
}
//cout<<r+1<<endl;
/*
if(l-1!=R)
{
cnt++;
L=l+1;
}
else break;
if(cnt>k)
{
f=0;
break;
}
if(L==R)break;*/
if(r==m+1)break;
cout<<"<<"<<r<<endl;
cnt++;
L=r+1;
}
//cout<<cnt<<endl;
//if(f)ans++;
if(cnt>k) {
ans++;
cout<<"ok"<<endl;
}
}
cout<<ans<<endl;
}
}
/*
6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan
8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
6 2
output:
0 0
result:
wrong answer 1st numbers differ - expected: '18', found: '0'