D. Chips Challenge
Problem ID: chips A prominent microprocessor company has enlisted your help to lay out some interchangeable components (widgets) on some of their computer chips. Each chip’s design is an N ×N square of slots. One slot can hold a single component, and you ar...
Problem Statement
Formatted from the contest statement text, with sample tests broken out into copyable blocks.
A prominent microprocessor company has enlisted your help to lay out some interchangeable components (widgets) on some of their computer chips. Each chip’s design is an N ×N square of slots. One slot can hold a single component, and you are to try to fit in as many widgets as possible. Modern processor designs are complex, of course. You unfortunately have several restrictions:
- Some of the slots are disabled.
- Some of the slots are already occupied by other components and cannot be used for widgets.
- There are sibling memory buses connected to the horizontal and vertical edges of the chip and their bandwidth loads need to match. As such, there must be exactly as many components in the first row as in the first column, exactly as many in the second row as in the second column, and so on. Component counts include both the components already specified on the chip and the added widgets.
- Similarly, the power supply is connected at the end of each row and column. To avoid hot spots, any given row or column must have no more than A/B of the total components on the chip for a given A and B.
A specification for a chip is N lines of N characters, where ‘.’ indicates an open slot, ‘/’ indicates a disabled slot, and ‘C’ indicates a slot already occupied by a component. For example:
CC/.. ./.// ..C.C /.C.. /./C/
If no more than 3/10 of the components may be in any one row or column, the maximum number of widgets that can be added to this 5 × 5 chip is 7. A possible arrangement is below, where ‘W’ indicates a widget added in an open slot.
CC/W. W/W// W.C.C /.CWW /W/C/
Input
The input consists of several test cases. Each case starts with a line containing three integers: The size of the chip N (1 ≤ N ≤ 40), and A and B (1 ≤ B ≤ 1000, 0 ≤ A ≤ B) as described above. Each of the following N lines contains N characters describing the slots, one of ‘.’, ‘/’ or ‘C’, as described above. The last test case is followed by a line containing three zeros.
ICPC 2011 World Finals Problem D: Chips Challenge
Output
For each test case, display a single line beginning with the case number. If there is a solution, display the maximum number of widgets that can be added to the chip. Display “impossible” if there is no solution. Follow the format of the sample output.
Sample Tests
2 1 1
/.
//
2 50 100
/.
C/
2 100 100
./
C.
5 3 10
CC/..
././/
..C.C
/.C..
/./C/
5 2 10
CC/..
././/
..C.C
/.C..
/./C/
0 0 0
ICPC 2011 World Finals Problem D: Chips Challenge Case 1: 0
Case 2: 1
Case 3: impossible
Case 4: 7
Case 5: impossible 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/2011/D-chips-challenge/solution.texC++ implementationcompetitive_programming/icpc/2011/D-chips-challenge/solution.cppStatement textcompetitive_programming/icpc/2011/D-chips-challenge/statement.txtStatement PDFcompetitive_programming/icpc/2011/D-chips-challenge/statement.pdfMetadatacompetitive_programming/icpc/2011/D-chips-challenge/meta.jsonYear packetcompetitive_programming/icpc/2011/contest_problems.pdf