All ICPC entries
Competitive Programming

ICPC 2016 - C. Ceiling Function

State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.

Source sync Apr 19, 2026
Track ICPC
Year 2016
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2016/C-ceiling-function
ICPC2016TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2016/C-ceiling-function. Edit competitive_programming/icpc/2016/C-ceiling-function/solution.tex to update the written solution and competitive_programming/icpc/2016/C-ceiling-function/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 C
                                         Ceiling Function
                                        Time limit: 5 seconds
Advanced Ceiling Manufacturers (ACM) is analyzing the properties of its new series of Incredibly
Collapse-Proof Ceilings (ICPCs). An ICPC consists of n layers of material, each with a different value
of collapse resistance (measured as a positive integer). The analysis ACM wants to run will take the
collapse-resistance values of the layers, store them in a binary search tree, and check whether the shape
of this tree in any way correlates with the quality of the whole construction. Because, well, why should
it not?
To be precise, ACM takes the collapse-resistance values for the layers, ordered from the top layer to the
bottom layer, and inserts them one-by-one into a tree. The rules for inserting a value v are:

    • If the tree is empty, make v the root of the tree.
    • If the tree is not empty, compare v with the root of the tree. If v is smaller, insert v into the left
      subtree of the root, otherwise insert v into the right subtree.

ACM has a set of ceiling prototypes it wants to analyze by trying to collapse them. It wants to take each
group of ceiling prototypes that have trees of the same shape and analyze them together.
For example, assume ACM is considering five ceiling prototypes with three layers each, as described
by Sample Input 1 and shown in Figure C.1. Notice that the first prototype’s top layer has collapse-
resistance value 2, the middle layer has value 7, and the bottom layer has value 1. The second prototype
has layers with collapse-resistance values of 3, 1, and 4 – and yet these two prototypes induce the same
tree shape, so ACM will analyze them together.
Given a set of prototypes, your task is to determine how many different tree shapes they induce.

          (2, 7, 1)            (3, 1, 4)            (1, 5, 9)         (2, 6, 5)         (9, 7, 3)
               2                    3              1                    2                         9

         1          7         1           4                5                 6               7

                                                               9        5              3

         Figure C.1: The four tree shapes induced by the ceiling prototypes in Sample Input 1.

Input

The first line of the input contains two integers n (1 ≤ n ≤ 50), which is the number of ceiling
prototypes to analyze, and k (1 ≤ k ≤ 20), which is the number of layers in each of the prototypes.
The next n lines describe the ceiling prototypes. Each of these lines contains k distinct integers (between
1 and 106 , inclusive), which are the collapse-resistance values of the layers in a ceiling prototype, ordered
from top to bottom.

Output

Display the number of different tree shapes.

 Sample Input 1                                Sample Output 1
 5   3                                         4
 2   7   1
 3   1   4
 1   5   9
 2   6   5
 9   7   3

 Sample Input 2                                Sample Output 2
 3 4                                           2
 3 1 2 40000
 3 4 2 1
 33 42 17 23

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

  1. Describe the data structures and the state maintained by the algorithm.

  2. Explain the processing order and why it is sufficient.

  3. 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.

C++ competitive_programming/icpc/2016/C-ceiling-function/solution.cpp

Exact copied implementation source.

Raw file
#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.

TeX write-up competitive_programming/icpc/2016/C-ceiling-function/solution.tex

Exact copied write-up source.

Raw file
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}

\title{ICPC World Finals 2016\\C. Ceiling Function}
\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}