QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718075#8334. GenexinlengweishangWA 0ms11964kbC++203.3kb2024-11-06 19:38:122024-11-06 19:38:14

Judging History

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

  • [2024-11-06 19:38:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11964kb
  • [2024-11-06 19:38:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e9 + 5;
const long long M1 = 998244353ll, M2 = 19260817ll, d1 = 233ll, d2 = 2333ll;

ll f1[309][60009], f2[309][60009], t1[60009], t2[60009], di1[60009], di2[60009];
string st[309], s;
ll flag, chunk[25], ck, n, m, q;
ll temp;
void gan(int l, int r, int k, int c)
{
	
//    cout<<k<<" "<<l<<" "<<r<<" "<<c<<" "<<chunk[c]<<" \n";
    if(chunk[c]>ck){
    	flag=20;
    	return ;
	}
    if (r - l + 1 <= 2)
    {
        // cout<<"&"<<l<<"---"<<r<<endl;
        for (int i = l; i <= r; i++)
            if (st[k][i-1] != s[i-1]){
                flag++;
                // cout<<"&"<<i<<endl;
            }
                
        return;
    }
    if (flag > ck)
        return;

    ll s1 = (f1[k][r] - f1[k][l - 1]+M1)%M1;
    ll s2 = (f2[k][r] - f2[k][l - 1]+M2)%M2;
    ll s3 = (t1[r] - t1[l - 1]+M1)%M1;
    ll s4 = (t2[r] - t2[l - 1]+M2)%M2;
    if (s1 == s3 && s2 == s4)
        return;
        

    int mid = (l + r) >> 1;
    
    s1 = (f1[k][mid] - f1[k][l - 1]+M1)%M1;
    s2 = (f2[k][mid] - f2[k][l - 1]+M2)%M2;
    s3 = (t1[mid] - t1[l - 1]+M1)%M1;
    s4 = (t2[mid] - t2[l - 1]+M2)%M2;
    // cout<<"#"<<l<<"--"<<mid<<":"<<s1<<" "<<s3<<" "<<s2<<" "<<s4<<endl;
    if (s1 != s3 || s2 != s4)
    {
        chunk[c + 1]++;
        gan(l, mid, k, c + 1);
    }
    
    if (flag > ck)
        return;
        
    s1 = (f1[k][r] - f1[k][mid]+M1)%M1;
    s2 = (f2[k][r] - f2[k][mid]+M2)%M2;
    s3 = (t1[r] - t1[mid]+M1)%M1;
    s4 = (t2[r] - t2[mid]+M2)%M2;
    //  cout<<"#"<<mid+1<<"--"<<r<<":"<<s1<<" "<<s3<<" "<<s2<<" "<<s4<<endl;
    if (s1 != s3 || s2 != s4)
    {
        chunk[c + 1]++;
        gan(mid + 1, r, k, c + 1);
    }
}

int main()
{
    scanf("%lld%lld%lld%lld", &n, &q, &m, &ck);
    char ch = getchar();
    di1[0] = 1;
    di2[0] = 1;
    for (int i = 1; i <= m; i++)
    {
        di1[i] = di1[i - 1] * d1;
        di1[i] %= M1;
        di2[i] = di2[i - 1] * d2;
        di2[i] %= M2;
    }
    for (int i = 1; i <= n; i++)
    {
        getline(cin, st[i]);
        f1[i][0]=0;
        f2[i][0]=0;
        for (int j = 1; j <= m; j++)
        {
            f1[i][j] = f1[i][j - 1]* d1 + st[i][j-1] ;
            f1[i][j] %= M1;
            f2[i][j] = f2[i][j - 1]* d2 + st[i][j-1] ;
            f2[i][j] %= M2;
            // cout<<f1[i][j]<<" ";
        }
        // cout<<endl;
    }
    while (q--)
    {
        // cout<<"\n!"<<q<<endl;
        getline(cin, s);
        int ans = 0;
        t1[0] = 0;
        t2[0] = 0;
        for (int j = 1; j <= m; j++)
        {
            t1[j] = t1[j - 1]* di1[j-1] + s[j-1] ;
            t1[j] %= M1;
            t2[j] = t2[j - 1]* di2[j-1] + s[j-1] ;
            t2[j] %= M2;
        }
        for (int i = 1; i <= n; i++)
        {
            flag = 0;
            temp=0;
            for(int i=1;i<20;i++) chunk[i]=0;
            gan(1, m, i, 1);
            if (flag <= ck)
                ans++;
//            if(m==15){
//            	printf("q=%d i=%d ",q,i);
//                for(int q=1;q<=15;q++) printf("%d ",chunk[q]);
//            	printf(" | ");
//			}
        }
//        if(m!=15)
        printf("%lld\n", ans);
    }
    return 0;
}
/*
6 4 4 1
kaki
kika 
manu
nana
tepu
tero
kaka
mana
teri
anan
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11964kb

input:

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

output:

1
1
1
0

result:

wrong answer 1st numbers differ - expected: '2', found: '1'