QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#514982#2273. Suffixes may Contain PrefixesPlentyOfPenalty#WA 8ms10400kbC++201.9kb2024-08-11 14:06:512024-08-11 14:06:52

Judging History

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

  • [2024-08-11 14:06:52]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:10400kb
  • [2024-08-11 14:06:51]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define per(i, l, r) for (int i = (l), i##end = (r); i >= i##end; --i)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define log(...) (void(0))
#define endl '\n'
#endif
using namespace std;
using ll = long long;
using lf = long double;
using lll = __int128;
using ull = unsigned long long;
const int N = 2010;
const int S = 3;
int n, m, t[N], f[N][S + 1], s[N][S + 1];
int ns, nt;
int pn[N];
ll dp[N][N], ans;
string tar;
void ZF() {
  int mi = 2, mt = 1;
  pn[1] = 0;
  for (int i = 2; i <= m; ++i) {
    if (i <= mt) pn[i] = min(pn[i - mi + 1], mt - i + 1);
    else
      pn[i] = 0;
    while (i + pn[i] <= m && t[i + pn[i]] == t[1 + pn[i]]) ++pn[i];
    if (i + pn[i] - 1 > mt) mt = i + pn[i] - 1, mi = i;
    // log("pn %d=%d\n", i, pn[i]);
  }
  pn[1] = m;
}
void Upd(ll &x, ll y) { x = max(x, y); }
int main() {
#ifdef memset0
  freopen("K.in", "r", stdin);
#endif
  cin.tie(0)->sync_with_stdio(0);
  cin >> tar >> n;
  m = tar.size();
  for (int i = 1; i <= m; ++i) t[i] = tar[i - 1] - 'a';
  ZF();
  for (int i = 0; i <= m; ++i) {
    ns = 0;
    for (int j = 1; j <= i + 1; ++j) {
      nt = min(i - j + 1, pn[j]);
      if (j + nt - 1 == i && !f[i][t[nt + 1]]) {
        f[i][t[nt + 1]] = nt + 1;
        s[i][t[nt + 1]] = ns;
      }
      ns += nt;
    }
    for (int j = 0; j <= S; ++j) {
      if (!f[i][j]) s[i][j] = ns;
      // log("F %d %d=%d,S=%d\n", i, j, f[i][j], s[i][j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m && j <= i; ++j) {
      // dp[i][j];
      for (int k = 0; k < S; ++k) Upd(dp[i + 1][f[j][k]], dp[i][j] + s[j][k]);
    }
  }
  for (int i = 0; i <= m && i <= n; ++i) ans = max(ans, dp[n][i] + s[i][S]);
  cout << ans << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4640kb

input:

fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...

output:

852

result:

ok single line: '852'

Test #2:

score: -100
Wrong Answer
time: 8ms
memory: 10400kb

input:

ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...

output:

3243

result:

wrong answer 1st lines differ - expected: '5894', found: '3243'