ICPC 2015 - E. Evolution in Parallel
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
Source-first archive entry
This page is built from the copied files in competitive_programming/icpc/2015/E-evolution-in-parallel. Edit
competitive_programming/icpc/2015/E-evolution-in-parallel/solution.tex to update the written solution and
competitive_programming/icpc/2015/E-evolution-in-parallel/solution.cpp to update the implementation.
The website does not replace those files with hand-maintained HTML. It reads the copied source tree during the build and exposes the exact files below.
Problem Statement
Copied statement text kept beside the solution archive for direct reference.
Problem E
Evolution in Parallel
Time limit: 2 seconds
It is 2178, and alien life has been discovered on a distant planet. There seems to be only one species on
the planet and they do not reproduce as animals on Earth do. Even more amazing, the genetic makeup
of every single organism is identical!
The genetic makeup of each organism is a single sequence of nucleotides. The nucleotides come in three
types, denoted by ‘A’ (Adenine), ‘C’ (Cytosine), and ‘M’ (Muamine). According to one hypothesis,
evolution on this planet occurs when a new nucleotide is inserted somewhere into the genetic sequence
of an existing organism. If this change is evolutionarily advantageous, then organisms with the new
sequence quickly replace ones with the old sequence.
It was originally thought that the current species evolved this way from a single, very simple organism
with a single-nucleotide genetic sequence, by way of mutations as described above. However, fossil
evidence suggests that this might not have been the case. Right now, the research team you are working
with is trying to validate the concept of “parallel evolution” – that there might actually have been two
evolutionary paths evolving in the fashion described above, and eventually both paths evolved to the
single species present on the planet today. Your task is to verify whether the parallel evolution hypothesis
is consistent with the genetic material found in the fossil samples gathered by your team.
Input
The input begins with a number n (1 ≤ n ≤ 4 000) denoting the number of nucleotide sequences found
in the fossils. The second line describes the nucleotide sequence of the species currently living on the
planet. Each of the next n lines describes one nucleotide sequence found in the fossils.
Each nucleotide sequence consists of a string of at least one but no more than 4 000 letters. The strings
contain only upper-case letters A, C, and M. All the nucleotide sequences, including that of the currently
live species, are distinct.
Output
Display an example of how the nucleotide sequences in the fossil record participate in two evolution-
ary paths. The example should begin with one line containing two integers s1 and s2 , the number of
nucleotide sequences in the fossil record that participate in the first path and second path, respectively.
This should be followed by s1 lines containing the sequences attributed to the first path, in chronological
order (from the earliest), and then s2 lines containing the sequences attributed to the second path, also
in chronological order. If there are multiple examples, display any one of them. If it is possible that a
sequence could appear in the genetic history of both species, your example should assign it to exactly
one of the evolutionary paths.
If it is impossible for all the fossil material to come from two evolutionary paths, display the word
impossible.
Sample Input 1 Sample Output 1
5 1 4
AACCMMAA MM
ACA A
MM AA
ACMAA ACA
AA ACMAA
A
Sample Input 2 Sample Output 2
3 impossible
ACMA
ACM
ACA
AMA
Sample Input 3 Sample Output 3
1 impossible
AM
MA
Sample Input 4 Sample Output 4
4 0 4
AAAAAA A
AA AA
AAA AAA
A AAAAA
AAAAA
Editorial
Rendered from the copied solution.tex file. The original TeX source remains
available below.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
Exact copied C++ implementation from solution.cpp.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files
Exact copied source-of-truth files. Edit solution.tex for the write-up and solution.cpp for the implementation.
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}
\title{ICPC World Finals 2015\\E. Evolution in Parallel}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Problem Summary}
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
\section*{Key Observations}
\begin{itemize}[leftmargin=*]
\item Write the structural observations that make the problem tractable.
\item State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
\item If the constraints matter, explain exactly which part of the solution they enable.
\end{itemize}
\section*{Algorithm}
\begin{enumerate}[leftmargin=*]
\item Describe the data structures and the state maintained by the algorithm.
\item Explain the processing order and why it is sufficient.
\item Mention corner cases explicitly if they affect the implementation.
\end{enumerate}
\section*{Correctness Proof}
We prove that the algorithm returns the correct answer.
\paragraph{Lemma 1.}
State the first key claim.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Lemma 2.}
State the next claim if needed.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Theorem.}
The algorithm outputs the correct answer for every valid input.
\paragraph{Proof.}
Combine the lemmas and finish the argument.
\section*{Complexity Analysis}
State the running time and memory usage in terms of the input size.
\section*{Implementation Notes}
\begin{itemize}[leftmargin=*]
\item Mention any non-obvious implementation detail that is easy to get wrong.
\item Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
\end{itemize}
\end{document}
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}