QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#130072#801. 回文自动机jrjyy#0 2ms3692kbC++201.1kb2023-07-23 15:48:152023-07-23 15:48:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 15:48:19]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3692kb
  • [2023-07-23 15:48:15]
  • 提交

answer

/* pam.cpp */
#include <bits/stdc++.h>

using i64 = long long;
constexpr int N = 1e6 + 5;
struct PAM {
    struct Node {
        int len, fa, cnt;
        std::array<int, 26> nx;
    } t[N]; int cnt = 2;
    PAM() { t[0].fa = 1, t[0].nx.fill(1), t[1].len = -1; }
    void build(const std::string &s) {
        int p = 1;
        for (int i = 0; i < int(s.size()); ++i) {
            auto find = [&](int x) {
                while (s[i] != s[i - t[x].len - 1]) x = t[x].fa;
                return x;
            };
            p = find(p); int c = s[i] - 'a';
            if (!t[p].nx[c])
                t[p].nx[c] = cnt, t[cnt].fa = find(t[p].fa), t[cnt].len = t[p].len + 2, ++cnt;
            p = t[p].nx[c], ++t[p].cnt;
        }
    }
    void work() {
        for (int i = cnt; i--; ) t[t[i].fa].cnt += t[i].cnt;
        i64 ans = 0;
        for (int i = 2; i < cnt; ++i) ans = std::max(ans, 1ll * t[i].len * t[i].len * t[i].cnt);
        std::cout << ans << '\n';
    }
} pam;

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    std::string s; std::cin >> s;
    pam.build(s), pam.work();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

4772

result:

wrong answer expected '5594', found '4772'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%