← CSES Better

Fence - INOI 2017

INOI · 2017 · Indian National Olympiad in Informatics · TINOI17A

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

grid · connected-components · geometry

The organizer’s problem statement is available at the official source link.

component perimeter

Fence only the exposed sides of potato patches

Four-neighbor connected potato fields form patches. Count exposed sides for each patch and report the largest perimeter.

Problem grid; highlighted cells show the illustrated path
.P.
PP.
.P.
  1. 1

    Find each patch

    Flood-fill cultivated fields using shared-edge adjacency.
  2. 2

    Count exposed sides

    A side contributes when its neighbor is uncultivated or outside the farm.
  3. 3

    Keep the largest perimeter

    Sum exposed sides per patch and report the maximum, not the total over all patches.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.