QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706631#8334. GeneAnneliese#TL 0ms0kbC++142.1kb2024-11-03 12:42:582024-11-03 12:42:59

Judging History

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

  • [2024-11-03 12:42:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-03 12:42:58]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
using ULL =unsigned long long;
using ll = long long;
const int N = 1005;
const int M = 60010;
#define rep(i,a ,b )  for(int i = a ;i<=b;i++)
#define pre(i,a ,b )  for(int i = a ;i>=b;i--)
pair<int, int> b[N];
vector<pair<int, int> > ans;
int  a[N], c[N];

#define pb push_back
int n, q, m, k;
LL P = 131;
string s[505];
ULL h[500][M],p[M];
ULL ht[M];
string t;

ULL get1(int l, int r,int idx) {
    return h[idx][r] - h[idx][l - 1] * p[r - l + 1];
}
ULL get(int l, int r) {
    return ht[r] - ht[l - 1] * p[r - l + 1];
}

/*
int ch(int idx,int ll,int rr) {
    int l = ll -1, r = rr + 1;
    while (l + 1 <  r) {
        int mid = (l + r) / 2;
        if (get1(l,r ,idx) == get(l,r)) l = mid;
        else r = mid;
    }
    return l;
}
*/

int ch(int idx, int le, int ri)
{
    while (le < ri)
    {
        int mid = (le + ri) >> 1;
        if (get1(le, mid, idx) == get(le, mid)) le = mid + 1;
        else ri = mid;
    }
    if (s[idx][le] == t[le]) return m + 1;
    else return le;
}

void solve()
{
    cin >> n >> q >> m >> k;
   
    p[0] = 1;
    rep(i, 1, m) {
        p[i] = p[i - 1 ] * P;
    }
    rep(i, 1, n) {
        cin >> s[i];
        s[i] = " " + s[i];
        rep(j, 1, m) {
            h[i][j] = h[i][j - 1] * P + s[i][j];
        }

    }
  
    while (q){
        int ans = 0;
      
        cin >> t;
        
        t = " " + t;

        rep(i, 1, m) {
            ht[i] = ht[i - 1] * P + t[i];
        }
      
        rep(i, 1, n) {
            int cnt = 0;
            int idx = ch(i,1,m);

            while (idx <= m)
            {
                cnt++;
                if (idx < m) {
                    idx = ch(i, idx + 1, m);
                }
                else break;
            }
            if (cnt <= k) ans++;
        }
        cout << ans << "\n";
    }
   

}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    srand(time(nullptr));

    int t = 1;
  //  cin >> t;

    while (t--) {
        solve();
    }

    return 0;


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

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

output:

2
2
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result: