Task: | Longest palindrome |
Sender: | aalto2024j_002 |
Submission time: | 2024-11-06 16:56:33 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.03 s | details |
#4 | ACCEPTED | 0.03 s | details |
#5 | ACCEPTED | 0.03 s | details |
#6 | ACCEPTED | 0.03 s | details |
#7 | ACCEPTED | 0.04 s | details |
#8 | ACCEPTED | 0.03 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.01 s | details |
#11 | ACCEPTED | 0.01 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result] 66 | scanf("%s", s); | ~~~~~^~~~~~~~~
Code
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=1000005; char Ma[2*N]; int Mp[2*N]; void Manacher(char s[], int len) { int l = 0; Ma[l++] = '$'; Ma[l++] = '#'; for(int i=0; i<len; i++) { Ma[l++] = s[i]; Ma[l++] = '#'; } Ma[l] = 0; int mx = 0, id = 0; for(int i=0; i<l; i++) { if(mx > i) Mp[i] = min(Mp[2*id - i], mx-i); else Mp[i] = 1; while(Ma[i + Mp[i]] == Ma[i - Mp[i]]) Mp[i]++; if(Mp[i]+i > mx) { mx = i+Mp[i]; id = i; } } mx = 0, id = 0; for(int i=0; i<l; i++) if(Mp[i] > mx) { mx = Mp[i]; id = i; } vector<char> ans; for(int i = 1; i<mx; i++) { char c = Ma[id - i]; if(c != '#' && c != '$') ans.push_back(c); } reverse(ans.begin(), ans.end()); for(char c: ans) putchar(c); if(Ma[id] != '#') putchar(Ma[id]); reverse(ans.begin(), ans.end()); for(char c: ans) putchar(c); } char s[N]; int main() { // Test(); scanf("%s", s); int len = strlen(s); Manacher(s, len); return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
aaaaaaaaaa |
correct output |
---|
aaaaaaaaaa |
user output |
---|
aaaaaaaaaa |
Test 2
Verdict: ACCEPTED
input |
---|
ababababab |
correct output |
---|
ababababa |
user output |
---|
ababababa |
Test 3
Verdict: ACCEPTED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
Test 4
Verdict: ACCEPTED
input |
---|
ababababababababababababababab... |
correct output |
---|
ababababababababababababababab... |
user output |
---|
ababababababababababababababab... |
Test 5
Verdict: ACCEPTED
input |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
correct output |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
user output |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
Test 6
Verdict: ACCEPTED
input |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
correct output |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
user output |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
Test 7
Verdict: ACCEPTED
input |
---|
abaabaaaaaaabaababbbbbbabaaabb... |
correct output |
---|
babbbabbbaabbbbaabbbbbbbbaabbb... |
user output |
---|
babbbabbbaabbbbaabbbbbbbbaabbb... |
Test 8
Verdict: ACCEPTED
input |
---|
txolestmgyepwrpofxyesjtsfkhjac... |
correct output |
---|
yxnbaabnxy |
user output |
---|
yxnbaabnxy |
Test 9
Verdict: ACCEPTED
input |
---|
ihpohpzoffel |
correct output |
---|
ff |
user output |
---|
ff |
Test 10
Verdict: ACCEPTED
input |
---|
flexflexvpqxierullgcfckjqflexf... |
correct output |
---|
cfc |
user output |
---|
cfc |
Test 11
Verdict: ACCEPTED
input |
---|
aabbabaabbaababbabaababbaabbab... |
correct output |
---|
abaababbaabbabaababbabaabbaaba... |
user output |
---|
abaababbaabbabaababbabaabbaaba... |
Test 12
Verdict: ACCEPTED
input |
---|
obsession |
correct output |
---|
ses |
user output |
---|
ses |
Test 13
Verdict: ACCEPTED
input |
---|
abcxcbaxcba |
correct output |
---|
abcxcba |
user output |
---|
abcxcba |
Test 14
Verdict: ACCEPTED
input |
---|
zzabc |
correct output |
---|
zz |
user output |
---|
zz |
Test 15
Verdict: ACCEPTED
input |
---|
aaccaabbaaccaaccaabbaaccaa |
correct output |
---|
aaccaabbaaccaaccaabbaaccaa |
user output |
---|
aaccaabbaaccaaccaabbaaccaa |
Test 16
Verdict: ACCEPTED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |