CSES - Aalto Competitive Programming 2024 - wk9 - Wed - Results
Submission details
Task:Longest palindrome
Sender:aalto2024j_002
Submission time:2024-11-06 16:52:08 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3--details
#4--details
#5--details
#6--details
#7ACCEPTED0.04 sdetails
#8ACCEPTED0.03 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11--details
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16--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:

input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
(empty)

Test 4

Verdict:

input
ababababababababababababababab...

correct output
ababababababababababababababab...

user output
(empty)

Test 5

Verdict:

input
aztdvxzjwxtrludymvpradgbdpgnrq...

correct output
aztdvxzjwxtrludymvpradgbdpgnrq...

user output
(empty)

Test 6

Verdict:

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:

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:

input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
(empty)