WA 30pts 求调
查看原帖
WA 30pts 求调
1241185
yi105011楼主2025/1/19 15:38
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n , m[110] , a[1010][110] , b[1010][110] , c[110] , kmp[110] , k , ans;
bool ff (int a[] , int m , int l) {
    int j = 0;
    for (int i = 1;i < m;i ++) {
        while (j && c[j] != a[i]) j = kmp[j];
        if (c[j] == a[i]) j ++;
        if (j == l) return true;
    }
    return false;
}
bool f (int l) {
    for (int i = 2;i <= n;i ++) {
        if ( !ff (b[i] , m[i] , l) ) return false;
    }
    return true;
}
signed main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> m[i];
        for (int j = 1;j <= m[i];j ++) {
            cin >> a[i][j];
        }
        for (int j = 1;j < m[i];j ++) {
            b[i][j] = a[i][j + 1] - a[i][j]; //cout << b[i][j] << ' ';
        }
        //cout << '\n';
    }
    for (int l = 1;l < m[1];l ++) {
        k = m[1] - l;
        for (int i = l;i < m[1];i ++) c[i - l] = b[1][i];
        for (int i = 1;i < k;i ++) {
            int j = kmp[i];
            while (j && c[j] != c[i]) j = kmp[j];
            if (c[j] == c[i]) kmp[i + 1] = j + 1;
            else kmp[i + 1] = 0;
        }
        for (int r = l;r < m[1];r ++) {
            if ( f (r - l + 1) ) ans = max (r - l + 1 , ans);
        }
    }
    cout << ans + 1;
    return 0;
}


提交记录

2025/1/19 15:38
加载中...