0% found this document useful (0 votes)
5 views2 pages

pali2 (en)

The document describes a problem where Professor BP needs to restore a sequence of integers by replacing erased numbers with a chosen integer x to maximize the length of the longest palindromic contiguous substring. The input consists of the number of integers and the sequence itself, where erased numbers are represented by -1. The output is a single integer representing the maximum length of the palindrome that can be achieved after the replacements.

Uploaded by

MATEI B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

pali2 (en)

The document describes a problem where Professor BP needs to restore a sequence of integers by replacing erased numbers with a chosen integer x to maximize the length of the longest palindromic contiguous substring. The input consists of the number of integers and the sequence itself, where erased numbers are represented by -1. The output is a single integer representing the maximum length of the palindrome that can be achieved after the replacements.

Uploaded by

MATEI B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

I ( O T IIOT2025 – Round 4

+ I ) ; Online, February 6-7th, 2025 pali2 • EN

Longest Palindrome (pali2)


Professor BP loves palindromes. He wrote a sequence V of N positive integers on the blackboard and
was delighted to see that it contained long palindromic substrings.

Figure 1: Professor BP writing his beautiful sequence.

However, during the break, one of his students erased some of the numbers from the sequence. Now,
Professor BP wants to restore the sequence by replacing all the erased numbers with the same number x
of his choice.
Your task is to determine the length of the longest palindromic contiguous substring that can be
obtained after choosing an optimal value for x.

☞ Among the attachments of this task you may find a template file pali2.* with a sample
incomplete implementation.

Input
The input file consists of two lines:

• a line containing integer N .

• a line containing the N integers V0 , . . . , VN −1 . If the number at position i is erased, Vi = −1,


otherwise Vi is a number between 1 and N .

Output
Print a single integer: the length of the longest contiguous palindromic substring that can be obtained
after replacing all erased numbers with the same number x of Professor BP’s choice.

Constraints

pali2 Page 1 of 2
• 1 ≤ N ≤ 200 000.
• −1 ≤ Vi ≤ N and Vi ̸= 0 for each i = 0 . . . N − 1.

Scoring
Your program will be tested against several test cases grouped in subtasks. In order to obtain the score
of a subtask, your program needs to correctly solve all of its test cases.
– Subtask 1 (0 points) Examples.

– Subtask 2 (11 points) N ≤ 50.

– Subtask 3 (25 points) N ≤ 1000.

– Subtask 4 (64 points) No additional limitations.


Examples
input output

10 5
6 5 5 -1 2 -1 4 5 -1 -1

Explanation
If Professor BP replaces all the erased numbers with the number 4, he obtains the sequence

6 5 5 4 2 4 4 5 4 4

The last 5 numbers form a palindromic sequence (4 4 5 4 4) and it is the longest he can achieve.

pali2 Page 2 of 2

You might also like