QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64752#801. 回文自动机zhoukangyang#0 4ms9636kbC++111.0kb2022-11-25 15:02:542022-11-25 15:02:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 15:02:57]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:9636kb
  • [2022-11-25 15:02:54]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i) 
#define R(i, j, k) for(int i = (j); i >= (k); --i) 
#define ll long long 
#define vi vector < int > 
#define sz(a) ((int) (a).size()) 
#define me(a, x) memset(a, x, sizeof(a)) 
using namespace std;
const int N = 2e6 + 7;
int n, m;
char s[N];

int p, ch[N][26], len[N], fa[N], lst, tot = 1;

int getfa(int x) {
	for(; p - len[x] - 1 < 1 || s[p - len[x] - 1] != s[p]; x = fa[x]) ;
	return x;
}

void ins() {
	lst = getfa(lst);
	if(!ch[lst][s[p] - 'a']) 
		++tot, 
		fa[tot] = ch[lst][s[p] - 'a'], 
		len[tot] = len[lst] + 2, 
		ch[lst][s[p] - 'a'] = tot;
	lst = ch[lst][s[p] - 'a'];
}
int cnt[N];

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> (s + 1);
	n = strlen(s + 1);
	fa[0] = 1, len[1] = -1;
	L(i, 1, n) 
		p = i, ins(), cnt[lst] += 1;
	R(i, tot, 1) 
		cnt[fa[i]] += cnt[i];
	ll ns = 0;
	L(i, 2, tot)
		ns = max(ns, (ll) cnt[i] * len[i] * len[i]);
	cout << ns << '\n';
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 9636kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

3978

result:

wrong answer expected '5594', found '3978'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%