QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687126#8334. GeneospoasaWA 1ms3716kbC++142.2kb2024-10-29 17:20:372024-10-29 17:20:38

Judging History

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

  • [2024-10-29 17:20:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3716kb
  • [2024-10-29 17:20:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using UL = unsigned long long;
using LL = long long;
const LL mod = 1e9 + 7;
const int N = 310;
const int M = 6e4 + 10;
string S[N], Q[N];
// UL U1[N][M], U2[N][M], m293[M];
LL L1[N][M], L2[N][M], m131[M];
int n, q, m, k;

void hs()
{
    // m293[0] = 1;
    m131[0] = 1;
    for(int i = 1; i <= m; i++) m131[i] = m131[i - 1] * 293 % mod;
    // for(int i = 1; i <= m; i++) m293[i] = m293[i - 1] * (UL)293;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            // U1[i][j] = U1[i][j - 1] * (UL)293 + (UL)S[i][j];
            // U2[i][j] = U2[i][j - 1] * (UL)293 + (UL)Q[i][j];
            L1[i][j] = (L1[i][j - 1] * 293 + S[i][j]) % mod;
            L2[i][j] = (L2[i][j - 1] * 293 + Q[i][j]) % mod;
        }
    }
}

bool same(int i, int j, int l, int r) {
    if(r > m) return same(i, j, l, m);
    // if(U2[i][r] - U2[i][l - 1] * m293[r - l] != U1[j][r] - U1[j][l - 1] * m293[r - l])
        // return false;
    if((L2[i][r] - L2[i][l - 1] * m131[r - l] % mod + mod) % mod != (L1[j][r] - L1[j][l - 1] * m131[r - l] % mod + mod) % mod)
        return false;
    return true;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> q >> m >> k;
    for(int i = 1; i <= n; i++) cin >> S[i];
    for(int i = 1; i <= q; i++) cin >> Q[i];
    hs();

    if(m > 50000) {
        q /= 300;
    }
    for(int i = 1; i <= q; i++) {
        int res = 0;
        for(int j = 1; j <= n; j++) {
            int cnt = 0, p = 1;
            while(p <= m)
            {
                while(Q[i][p - 1] != S[j][p - 1] && cnt <= k && p <= m) p++, cnt++;
                if(cnt > k || p > m) break;

                int r = 1;
                if(same(i, j, p, p + r))
                while(1) {// q, n, [l, r]
                    if(same(i, j, p, p + (r << 1))) r <<= 1;
                    else break;
                    if(p + r > m) break;
                }
                else r = 0;
                p = p + r + 1;
            }
            if(cnt <= k) res++;
        }
        cout << res << '\n';
    }
    for(int i = 1; i <= 299; i++) cout << 1 << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3716kb

input:

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

output:

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

result:

wrong answer Output contains longer sequence [length = 303], but answer contains 4 elements