QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259725#2273. Suffixes may Contain PrefixesPixelCat#WA 2ms5056kbC++202.1kb2023-11-21 12:05:402023-11-21 12:05:41

Judging History

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

  • [2023-11-21 12:05:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5056kb
  • [2023-11-21 12:05:40]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 2000;
const int INF = INT_MAX;

int dp[MAXN + 10][MAXN + 10];
vector<int> adj[MAXN + 10];
int val[MAXN + 10];

vector<int> build(string s) {
    vector<int> f(sz(s) + 1, 0);
    int k = 0;
    for(int i = 1; i < sz(s); i++) {
        while(k && s[k] != s[i]) k = f[k];
        if(s[k] == s[i]) k++;
        f[i + 1] = k;
    }
    return f;
}

vector<int> get_z(string s) {
    int n = sz(s);
    vector<int> Z(n);
    int l = 0, r = 0;
    for(int i = 0; i < n; i++) {
        Z[i] = max(min(Z[i - l], r - i), 0);
        while(i + Z[i] < sz(s) && s[Z[i]] == s[i + Z[i]]) {
            l = i; r = i + Z[i]; Z[i]++;
        }
        val[i + 1]++;
        val[i + Z[i]]--;
    }
    val[0] = 1;
    for(int i = 1; i <= n; i++) val[i] += val[i - 1];
    return Z;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s; cin >> s;
    int len; cin >> len;
    int n = sz(s);
    get_z(s);
    auto fail = build(s);
    for(int i = 0; i <= n; i++) {
        For(c, 0, 25) {
            int k = i;
            if(k == n) k = fail[k];
            while(k && char(c + 'a') != s[k]) k = fail[k];
            if(char(c + 'a') == s[k]) k++;
            adj[k].eb(i);
        }
    }
    For(i, 0, n) {
        sort(all(adj[i]));
        adj[i].erase(unique(all(adj[i])), adj[i].end());
        // cout << i << " ->";
        // for(auto &j:adj[i]) cout << " " << j;
        // cout << "\n";
    }
    For(i, 0, len) For(j, 0, n) dp[i][j] = -INF;
    dp[0][0] = 0;
    For(i, 1, len) For(j, 0, n) {
        for(auto &k:adj[j]) dp[i][j] = max(dp[i][j], dp[i - 1][k]);
        dp[i][j] += val[j];
    }
    int mx = 0;
    For(i, 0, n) mx = max(mx, dp[len][i]);
    cout << mx << "\n";
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5056kb

input:

fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...

output:

857

result:

wrong answer 1st lines differ - expected: '852', found: '857'