QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743605#8334. GenedodolaWA 0ms3884kbC++173.0kb2024-11-13 19:37:372024-11-13 19:37:37

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 19:37:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-11-13 19:37:37]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef double ld;
typedef unsigned long ul;
// typedef long long ll;
typedef unsigned long long ll;
typedef pair<ll, ll> pll;

const int maxn = 3e6 + 50;
const int inf = 0x3f3f3f;
const ll mo998 = 998244353;

vector<bool> isprime;
vector<ll> primes;
void init_primes() {
  isprime.assign(maxn + 1, true);
  isprime[0] = isprime[1] = false;
  for (ll i = 2; i <= maxn; i++) {
    if (!isprime[i])
      continue;
    for (ll j = 2; i * j <= maxn; j++) {
      isprime[i * j] = false;
    }
  }
}

ll b = 131;
vector<ll> pb;
vector<ll> get_hash(string s) {
  ll n = s.size();
  vector<ll> v(n + 1);
  v[0] = 0;
  for (int i = 0; i < n; i++) {
    ll x = s[i] - 'a';
    v[i + 1] = (v[i] + pb[i] * x);
  }
  return v;
}

ll n, q, m, k;
ll check(vector<ll> v1, vector<ll> v2, ll lp) {
  // lp是上一个不同的位置
  ll l = lp + 1, r = m + 1; // [l,r]
  while (l < r) {
    ll mid = (l + r) / 2;
    if (v1[mid] - v1[lp] == v2[mid] - v2[lp]) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  // 返回不同的那一位
  return l;
};

void solve() {
  cin >> n >> q >> m >> k;

  ll bb = 1;
  for (int i = 0; i <= m; i++) {
    pb.push_back(bb);
    bb *= b;
  }

  vector<vector<ll>> h1;
  string ss;
  for (int i = 0; i < n; i++) {
    cin >> ss;
    h1.push_back(get_hash(ss));
  }

  while (q--) {
    string s;
    cin >> s;
    if (k >= m) {
      cout << n << '\n';
      return;
    }
    vector<ll> hs = get_hash(s);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll p = 0, cnt = 0;
      // ll ki = k;
      bool flag = true;
      while (p + 1 <= m) {
        p = check(hs, h1[i], p);
        if (p > m)
          break;
        cnt++;
        if (cnt == k && hs[m] - hs[p] == h1[i][m] - h1[i][p]) {
          break;
        }
        if (cnt > k) {
          flag = false;
          break;
        }
      }
      // cout << p << ' ';
      if (flag) {
        ans++;
      }
    }
    cout << ans << '\n';
  }
}

// void init() {
//   // init_primes();
//   ll m = 4;
//   auto check = [&](vector<ll> v1, vector<ll> v2, ll lp) {
//     // lp是上一个不同的位置
//     ll l = lp + 1, r = m + 1; // [l,r)
//     while (l < r) {
//       ll mid = (l + r) / 2;
//       if (v1[mid] - v1[lp] == v2[mid] - v2[lp]) {
//         l = mid + 1;
//       } else {
//         r = mid;
//       }
//     }
//     // 返回不同的那一位
//     return l;
//   };
//   cout << check({0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}, 0) << '\n';
//   cout << check({0, 1, 2, 3, 4}, {0, 1, 2, 3, 5}, 0) << '\n';
//   cout << check({0, 1, 2, 3, 4}, {0, 1, 2, 4, 5}, 0) << '\n';
//   cout << check({0, 1, 2, 3, 4}, {0, 1, 3, 4, 5}, 0) << '\n';
//   cout << check({0, 1, 2, 3, 4}, {0, 2, 3, 4, 5}, 0) << '\n';
// }

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // init();
  int _t = 1;
  // cin >> _t;
  // cin.get();
  while (_t--)
    solve();

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

output:

2
2
1
0

result:

ok 4 number(s): "2 2 1 0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus

output:

1
1
2
2
1
2

result:

ok 6 numbers

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3884kb

input:

300 300 9 10
dmzampmxe
bteaudaxb
fjfwhhsfq
btnfzqtyp
ijjrkbyht
hkizlvgdc
ukwsnhiff
hacsdrwyl
fbjabnhst
ktsxbgbtg
jopdbsdsr
yxdxxjltd
daechsouq
klrglgwbn
llzhqzlor
ckdedutfn
lkjxcryoe
zvusjevtz
cevrcdltg
tdmmvvpkj
davfsweem
spcfhcitm
aohsfqrqh
lblehevpj
soaqryimp
tbxlulxmn
tnlzbkhda
ukfhjykuk
eghpuua...

output:

300

result:

wrong answer Answer contains longer sequence [length = 300], but output contains 1 elements