Gold
Batch
Editorial available
Silo Switchboard
/silo-switchboard
Version
v1
Published
Apr 23, 2026, 10:56 PM
Updated
Apr 23, 2026, 10:56 PM
Testsets
1
Statement
Rendered as plain statement text from the published version.
# Silo Switchboard
## Problem
The Cow State Fair has N grain silos that need to be configured for a special synchronized display. Each silo can be set to one of three states: **0** (idle), **1** (processing), or **2** (active).
You have a control system that can set each silo to any state, but each configuration change has a cost. Additionally, due to structural concerns about resonance, **no two adjacent silos may end in the same state**.
Given:
- The number of silos N
- A target state pattern (for reference)
- The cost matrix where `cost[i][j]` represents the cost to set silo `i` to state `j`
Find the **minimum total cost** to configure all silos such that no two adjacent silos have the same final state.
## Input Format
The first line contains a single integer **N** (1 ≤ N ≤ 1000), the number of silos.
The second line contains N space-separated integers representing the target state pattern (for reference only; you must find the minimum cost valid configuration, which may not match the target exactly).
The next N lines contain three space-separated integers each:
- Line i+2 contains `c0 c1 c2`, where `cj` is the cost to set silo `i` to state `j`.
All costs are non-negative integers ≤ 10^6.
## Output Format
Output a single integer: the minimum cost to configure all silos such that no two adjacent silos have the same final state.
## Constraints
- 1 ≤ N ≤ 1000
- 0 ≤ each cost ≤ 10^6
- All silos must be assigned a state from {0, 1, 2}
- For all adjacent pairs (i, i+1), the final states must differ
## Sample Input
```
3
1 2 0
3 0 2
2 1 5
0 2 1
```
## Sample Output
```
3
```
## Sample Explanation
With 3 silos and costs:
- Silo 0: costs [3, 0, 2] to set to states [0, 1, 2]
- Silo 1: costs [2, 1, 5] to set to states [0, 1, 2]
- Silo 2: costs [0, 2, 1] to set to states [0, 1, 2]
One optimal configuration is [2, 1, 0] (no adjacent silos are the same):
- Set silo 0 to state 2: cost 2
- Set silo 1 to state 1: cost 1 (state 1 ≠ 2, satisfies adjacency)
- Set silo 2 to state 0: cost 0 (state 0 ≠ 1, satisfies adjacency)
- **Total cost: 2 + 1 + 0 = 3**
Another optimal configuration is [1, 0, 2]:
- Set silo 0 to state 1: cost 0
- Set silo 1 to state 0: cost 2 (state 0 ≠ 1, satisfies adjacency)
- Set silo 2 to state 2: cost 1 (state 2 ≠ 0, satisfies adjacency)
- **Total cost: 0 + 2 + 1 = 3**
Both achieve the minimum possible cost while respecting the adjacency constraint.