benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2020_D / Gene Folding

Problem

Answer published by the source. Consult the official source to check your work against its answer.

platform

atcoder

question content

## Problem Statement International Cell Processing Company (ICPC) is a world leader in the analysis of genetic sequences. A genetic sequence is a sequence of nucleotides, which in this problem is represented by a string containing only the letters A, C, G, and T in some combination, each letter representing a single nucleotide (Adenine, Cytosine, Guanine, and Thymine, respectively). One of the key discoveries made by ICPC is that through a process called Genetically Optimized Organic Folding (GOOF), they can take a genetic sequence and transform it into a simpler one, while preserving many of the properties of the sequence that ICPC wants to analyze. A single application of GOOF works as follows. Find a point between two adjacent nucleotides in the nucleotide sequence, such that the sequence reads the same from that point in both directions, up until the nearer end of the sequence. For instance, in the sequence `ATTACC`, there are two such points: `AT-TACC` and `ATTAC-C`. Then pick one of these points (say, the first one), and fold the genetic sequence at that point, merging the identical nucleotides (so, in this case the `AT` and `TA` would become merged, and the resulting sequence would be `CCAT` or `TACC`). Through repeated application of GOOF, a nucleotide can potentially be made much shorter. However, manually searching for the appropriate folding points is very time-consuming. ICPC reached out to you to write a program that would automate the process of finding the folding points and choosing them so as to obtain the shortest possible genetic sequence from a given input sequence. ### Input The input contains a single string s s representing the nucleotide sequence to be analyzed. The string consists of characters A, C, G, and T only. The length of s s is between 1 and 4×106 4 \times 10^6 , inclusive. ### Output Output the smallest possible length of a sequence obtained from the input by applying GOOF zero or more times. ### Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem Statement

International Cell Processing Company (ICPC) is a world leader in the analysis of genetic sequences. A genetic sequence is a sequence of nucleotides, which in this problem is represented by a string containing only the letters A, C, G, and T in some combination, each letter representing a single nucleotide (Adenine, Cytosine, Guanine, and Thymine, respectively).

One of the key discoveries made by ICPC is that through a process called Genetically Optimized Organic Folding (GOOF), they can take a genetic sequence and transform it into a simpler one, while preserving many of the properties of the sequence that ICPC wants to analyze.

A single application of GOOF works as follows. Find a point between two adjacent nucleotides in the nucleotide sequence, such that the sequence reads the same from that point in both directions, up until the nearer end of the sequence. For instance, in the sequence `ATTACC`, there are two such points: `AT-TACC` and `ATTAC-C`. Then pick one of these points (say, the first one), and fold the genetic sequence at that point, merging the identical nucleotides (so, in this case the `AT` and `TA` would become merged, and the resulting sequence would be `CCAT` or `TACC`).

Through repeated application of GOOF, a nucleotide can potentially be made much shorter. However, manually searching for the appropriate folding points is very time-consuming. ICPC reached out to you to write a program that would automate the process of finding the folding points and choosing them so as to obtain the shortest possible genetic sequence from a given input sequence.

### Input

The input contains a single string s representing the nucleotide sequence to be analyzed. The string consists of characters A, C, G, and T only. The length of s is between 1 and 4×10⁶, inclusive.

### Output

Output the smallest possible length of a sequence obtained from the input by applying GOOF zero or more times.

### Sample Input 1

Original LaTeX notation
## Problem Statement

International Cell Processing Company (ICPC) is a world leader in the analysis of genetic sequences. A genetic sequence is a sequence of nucleotides, which in this problem is represented by a string containing only the letters A, C, G, and T in some combination, each letter representing a single nucleotide (Adenine, Cytosine, Guanine, and Thymine, respectively).

One of the key discoveries made by ICPC is that through a process called Genetically Optimized Organic Folding (GOOF), they can take a genetic sequence and transform it into a simpler one, while preserving many of the properties of the sequence that ICPC wants to analyze.

A single application of GOOF works as follows. Find a point between two adjacent nucleotides in the nucleotide sequence, such that the sequence reads the same from that point in both directions, up until the nearer end of the sequence. For instance, in the sequence `ATTACC`, there are two such points: `AT-TACC` and `ATTAC-C`. Then pick one of these points (say, the first one), and fold the genetic sequence at that point, merging the identical nucleotides (so, in this case the `AT` and `TA` would become merged, and the resulting sequence would be `CCAT` or `TACC`).

Through repeated application of GOOF, a nucleotide can potentially be made much shorter. However, manually searching for the appropriate folding points is very time-consuming. ICPC reached out to you to write a program that would automate the process of finding the folding points and choosing them so as to obtain the shortest possible genetic sequence from a given input sequence.

### Input

The input contains a single string \( s \) representing the nucleotide sequence to be analyzed. The string consists of characters A, C, G, and T only. The length of \( s \) is between 1 and \( 4 \times 10^6 \), inclusive.

### Output

Output the smallest possible length of a sequence obtained from the input by applying GOOF zero or more times.

### Sample Input 1

Code

ATTACC

### Sample Output 1

Code

3

### Sample Input 2

Code

AAAAGAATTAA

### Sample Output 2

Code

5

question title

Gene Folding

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import