EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2023
  3. Preliminary Round

Codey and Number Grid

https://www.hackerrank.com/contests/codenection-2023-preliminary-round-open-category/challenges/cn-c17

Question

Codey finds itself in a desolate planet. The planet, shrouded in mystery, is known for its harsh, alien terrain — a place where every decision is a matter of survival. Here, in this strange land, Codey discovers a m∗nm * nm∗n ( n rows and m columns) grid imprinted with unique numbers that seem to hold the keys to life itself.

Trapped on this planet, Codey faces a huge challenge. Its very survival depends on its ability to decipher this grid. It must uncover k, the maximum connected area within the grid that contains every number from 1 to k. Two cells can only be connected if they share an edge.

As time runs out and the situation becomes more dangerous, Codey needs your help to find k, the largest possible connected area k that meets the condition. Can you assist Codey in determining the value of k to survive this challenge?

Input Format

The first line contains two integers, n and m, where n represents the number of rows and m represents the columns in the 2D grid.

The following lines contain the numbers aija_{ij}aij​ , which provides a representation of the 2D grid.

Constraints

1≤n≤1031 \le n \le 10^31≤n≤103
1≤m≤1031 \le m \le 10^31≤m≤103
1≤aij≤1061 \le a_{ij} \le 10^61≤aij​≤106
  • Every aija_{ij}aij​ is guaranteed unique.

Output Format

Output k, the maximum connected area within the grid that contains every number from 1 to k.

Sample Inputs:

Input

3 3
1 2 7
9 3 11
8 4 5

Output

5

Explanation

The representation of the grid and the highlighted maximum area is as follows:

The selected area only consists of number from 1 to 5, hence the output is 5.

Input

3 3
1 2 3
10 4 11
6 8 5

Output

4

Solution - BFS

This is a typical breadth-first search question.

Step 1: find the coordinates of 1.

Step 2: find the 2, then rinse and repeat.

Then I haven't finish yet lmao.

PreviousCodey and Painted TreeNextCodey and Crimes

Last updated 2 months ago

🇲🇾