QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#745049#8334. GenedodolaRE 0ms0kbC++172.3kb2024-11-14 02:10:542024-11-14 02:10:54

Judging History

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

  • [2024-11-14 02:10:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-14 02:10:54]
  • 提交

answer

#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

typedef double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
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;
    }
  }
}

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

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

void solve() {
  cin >> n >> q >> m >> k;
  vector<vector<ull>> h1;
  string ss;
  for (int i = 0; i < n; i++) {
    cin >> ss;
    h1.push_back(get_hash(ss));
  }

  while (q--) {
    string s;
    cin >> s;
    vector<ull> 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 == -1) {
          break;
        }
        if (p > m)
          break;
        cnt++;
        if (cnt > k) {
          flag = false;
          break;
        }
      }
      if (flag) {
        ans++;
      }
    }
    cout << ans << '\n';
  }
}

void init() {
  // init_primes();
  ull bb = 1;
  pb.assign(60000, 0);
  for (int i = 0; i <= 60000; i++) {
    pb.push_back(bb);
    bb *= b;
  }
}

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

  return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

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

output:


result: