Task: | Longest palindrome |
Sender: | aalto2024j_002 |
Submission time: | 2024-11-06 16:52:08 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | TIME LIMIT EXCEEDED | -- | details |
#5 | TIME LIMIT EXCEEDED | -- | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | ACCEPTED | 0.04 s | details |
#8 | ACCEPTED | 0.03 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | TIME LIMIT EXCEEDED | -- | 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 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'void Test()': input/code.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result] 57 | freopen("temp\\in.txt", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ input/code.cpp: In function 'int main()': input/code.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result] 63 | 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; } string ans = ""; if(Ma[id] != '#') ans = Ma[id]; for(int i = 1; i<mx; i++) { char c = Ma[id - i]; if(c != '#' && c != '$') ans = c + ans + c; } cout << ans; } void Test() { freopen("temp\\in.txt", "r", stdin); } 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: TIME LIMIT EXCEEDED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
(empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
ababababababababababababababab... |
correct output |
---|
ababababababababababababababab... |
user output |
---|
(empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
correct output |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
user output |
---|
(empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
correct output |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
user output |
---|
(empty) |
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: TIME LIMIT EXCEEDED
input |
---|
aabbabaabbaababbabaababbaabbab... |
correct output |
---|
abaababbaabbabaababbabaabbaaba... |
user output |
---|
(empty) |
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: TIME LIMIT EXCEEDED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
(empty) |