QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719324#8334. GeneTheForsaking#RE 0ms0kbC++203.8kb2024-11-07 00:16:222024-11-07 00:16:22

Judging History

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

  • [2024-11-07 00:16:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-07 00:16:22]
  • 提交

answer

#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue> 
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <ctime>
#include <assert.h>
#include <deque>
#include <list>
#include <stack>

 
using namespace std;

#define is_mul_overflow(a, b) \
    ((b != 0) && (a > LLONG_MAX / b || a < LLONG_MIN / b))
 
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef pair<long long , long long> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<int, long long > pil;
typedef pair<long long, pii> plii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ull, ull> puu;
typedef long double ld;
const int N = 2000086, MOD = 1e9 + 9, INF = 0x3f3f3f3f, MID = 333;
const double EPS = 1e-5;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int n, m, cnt, w[N];
vector<ll> num;
ll res;

ll lowbit(ll x) { return x & -x; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline double rand(double l, double r) { return (double)rand() / RAND_MAX * (r - l) + l; }
inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
inline ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
inline double qmi(double a, ll b) { double res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } 
inline ll C(ll a, ll b) { if (a < b) return 0; if (b > a - b) b = a - b; ll res = 1; for (ll i = 1, j = a; i <= b; i++, j--) { res = res * (j % MOD) % MOD; res = res * qmi(i, MOD - 2, MOD) % MOD; } return res; }
inline ll C(ll a, ll b, int* c) { if (a < b) return 0; ll res = 1; for (ll j = a, i = 1; i < b + 1; i++, j--) res *= j; for (ll j = a, i = 1; i < b + 1; i++, j--) res /= i; return res; }
inline int find_(int x) { return lower_bound(num.begin(), num.end(), x) - num.begin(); }

struct pair_hash {
    template <class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& pair) const {
        return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
    }
};

ll h1[301][60008], ht[60008];
ll d1 = 131, mod1 = 805306457, p[N];
int q, K;
char s[301][60008], t[60008];

ll init() {
    p[0] = 1;
    for (int i = 1; i < N; i++) p[i] = p[i - 1] * d1 % mod1;
}

ll get(ll* h, int l, int r) {
    return (h[r] - h[l - 1] * p[r - l + 1] % mod1 + mod1) % mod1;
}

inline void solve() {
    while (q--) {
        scanf("%s", t + 1);
        for (int i = 1; i < m + 1; i++) ht[i] = (ht[i - 1] * d1 + t[i]) % mod1;
        res = 0;
        for (int i = 1; i < n + 1; i++) {
            int pos = 1, c = 0;
            while (c <= K && pos <= m) {
                ll a = get(h1[i], pos, m), b = get(ht, pos, m);
                if (a == b) break;
                int l = pos, r = m;
                while (l < r) {
                    int mid = l + r >> 1;
                    if (get(h1[i], pos, mid) == get(ht, pos, mid)) l = mid + 1;
                    else r = mid;
                }
                c++;
                pos = l + 1;
            }
            res += c <= K;
        }
        printf("%lld\n", res);
    }
}

int main() {
    init();
    cin >> n >> q >> m >> K;
    for (int i = 1; i < n + 1; i++) {
        scanf("%s", s[i] + 1);
        for (int j = 1; j < m + 1; j++) h1[i][j] = (h1[i][j - 1] * d1 + s[i][j]) % mod1;
    }
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: