J. Spin Doctor
As an employee of the world’s most respected political polling corporation, you must take complex, real- world issues and simplify them down to a few numbers. It isn’t always easy. A big election is coming up and, at the request of Candidate X, you have jus...
Problem Statement
Formatted from the contest statement text, with sample tests broken out into copyable blocks.
As an employee of the world’s most respected political polling corporation, you must take complex, real- world issues and simplify them down to a few numbers. It isn’t always easy. A big election is coming up and, at the request of Candidate X, you have just finished polling n people. You have gathered three pieces of information from each person, with the values for the ith person recorded as:
- ai – the number of digits of π they have memorized
- bi – the number of hairs on their head
- ci – whether they will vote for Candidate X
Unfortunately, you are beginning to wonder if these are really the most relevant questions to ask. In fact, you cannot see any correlation between a, b, and c in the data. Of course, you cannot just contradict your customer – that is a good way to lose your job! Perhaps the answer is to find some weighting formula to make the results look meaningful. You will pick two real values S and T , and sort the poll results (ai , bi , ci ) by the measure ai · S + bi · T . The sort will look best if the results having ci true are clustered as close to each other as possible. More precisely, if j and k are the indices of the first and last results with ci true, you want to minimize the cluster size which is k − j + 1. Note that some choices of S and T will result in ties among the (ai , bi , ci ) triples. When this happens, you should assume the worst possible ordering occurs (that which maximizes the cluster size for this (S, T ) pair).
Input
The input starts with a line containing n (1 ≤ n ≤ 250 000), which is the number of people polled. This is followed by one line for each person polled. Each of those lines contains integers ai (0 ≤ ai ≤ 2 000 000), bi (0 ≤ bi ≤ 2 000 000), and ci , where ci is 1 if the person will vote for Candidate X and 0 otherwise. The input is guaranteed to contain at least one person who will vote for Candidate X.
Output
Display the smallest possible cluster size over all possible (S, T ) pairs.
Sample Tests
6
0 10 0
10 0 1
12 8 1
5 5 0
11 2 1
11 3 0 4 10
6 1 1
0 2 0
2 1 1
6 1 1
8 2 0
4 4 0
4 0 0
2 3 1
6 1 0
6 3 1 8 5
5 7 0
3 4 0
5 7 0
5 7 1
9 4 0 1 Editorial
The solution write-up is rendered from the LaTeX source, with equations kept live through MathJax.
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
C++ solution used for this page.
#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 and Assets
Raw files are still available here when you want the original TeX, C++, or statement assets.
Show raw files
competitive_programming/icpc/2016/J-spin-doctor/solution.texC++ implementationcompetitive_programming/icpc/2016/J-spin-doctor/solution.cppStatement textcompetitive_programming/icpc/2016/J-spin-doctor/statement.txtStatement PDFcompetitive_programming/icpc/2016/J-spin-doctor/statement.pdfMetadatacompetitive_programming/icpc/2016/J-spin-doctor/meta.jsonYear packetcompetitive_programming/icpc/2016/contest_problems.pdf