All ICPC entries
Competitive Programming

ICPC 2015 - I. Ship Traffic

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 2015
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2015/I-ship-traffic
ICPC2015TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2015/I-ship-traffic. Edit competitive_programming/icpc/2015/I-ship-traffic/solution.tex to update the written solution and competitive_programming/icpc/2015/I-ship-traffic/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 I
                                              Ship Traffic
                                       Time limit: 3 seconds
Ferries crossing the Strait of Gibraltar from Morocco to Spain must carefully navigate to avoid the heavy
ship traffic along the strait. Write a program to help ferry captains find the largest gaps in strait traffic
for a safe crossing.
Your program will use a simple model as follows. The strait has several parallel shipping lanes in east-
west direction. Ships run with the same constant speed either eastbound or westbound. All ships in the
same lane run in the same direction. Satellite data provides the positions of the ships in each lane. The
ships may have different lengths. Ships do not change lanes and do not change speed for the crossing
ferry.
The ferry waits for an appropriate time when there is an adequate gap in the ship traffic. It then crosses
the strait heading northbound along a north-south line at a constant speed. From the moment a ferry
enters a lane until the moment it leaves the lane, no ship in that lane may touch the crossing line. Ferries
are so small you can neglect their size. Figure I.1 illustrates the lanes and ships for Sample Input 1. Your
task is to find the largest time interval within which the ferry can safely cross the strait.

                                                                                              N
                                                                                          W        E
                                                                                               S

                                                       Ferry

                                          Figure I.1: Sample Input 1.

Input

The first line of input contains six integers: the number of lanes n (1 ≤ n ≤ 105 ), the width w of each
lane (1 ≤ w ≤ 1 000), the speed u of ships and the speed v of the ferry (1 ≤ u, v ≤ 100), the ferry’s
earliest start time t1 and the ferry’s latest start time t2 (0 ≤ t1 < t2 ≤ 106 ). All lengths are given in
meters, all speeds are given in meters/second, and all times are given in seconds.
Each of the next n lines contains the data for one lane. Each line starts with either E or W, where E
indicates that ships in this lane are eastbound and W indicates that ships in this lane are westbound. Next
in the line is an integer mi , the number of ships in this lane (0 ≤ mi ≤ 105 for each 1 ≤ i ≤ n). It is
followed by mi pairs of integers lij and pij (1 ≤ lij ≤ 1 000 and −106 ≤ pij ≤ 106 ). The length of
ship j in lane i is lij , and pij is the position at time 0 of its forward end, that is, its front in the direction
it moves.
Ship positions within each lane are relative to the ferry’s crossing line. Negative positions are west of
the crossing line and positive positions are east of it. Ships do not overlap or touch, and are sorted in
increasing order of their positions. Lanes are ordered by increasing distance from the ferry’s starting
point, which is just south of the first lane. There is no space between lanes. The total number of ships is
at least 1 and at most 105 .

Output

Display the maximal value d for which there is a time s such that the ferry can start a crossing at any
time t with s ≤ t ≤ s + d. Additionally the crossing must not start before time t1 and must start no later
than time t2 . The output must have an absolute or relative error of at most 10−3 . You may assume that
there is a time interval with d > 0.1 seconds for the ferry to cross.

 Sample Input 1                                       Sample Output 1
 3   100 5 10 0 100                                   6.00000000
 E   2 100 -300 50 -100
 W   3 10 60 50 200 200 400
 E   1 100 -300

 Sample Input 2                                           Sample Output 2
 1 100 5 10 0 200                                         50.00000000
 W 4 100 100 100 300 100 700 100 900

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/2015/I-ship-traffic/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/2015/I-ship-traffic/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 2015\\I. Ship Traffic}
\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}