Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 940/C. How Does the Rook Move?
PrevNext
CodeforcesCodeforces
Expert
Codeforces Round 940

C. How Does the Rook Move?

Dynamic ProgrammingMatrixRecursion
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

You are given an π‘›Γ—𝑛 chessboard where you and the computer take turns alternatingly to place white rooks & black rooks on the board respectively. While placing rooks, you have to ensure that no two rooks attack each other. Two rooks attack each other if they share the same row or column regardless of color.

A valid move is placing a rook on a position (π‘Ÿ,𝑐) such that it doesn't attack any other rook.

You start first, and when you make a valid move in your turn, placing a white rook at position (π‘Ÿ,𝑐), the computer will mirror you and place a black rook at position (𝑐,π‘Ÿ) in its turn. If π‘Ÿ=𝑐, then the computer can't mirror your move, and skips its turn.

You have already played π‘˜ moves with the computer (the computer tries to mirror these moves too), and you must continue playing the game until there are no valid moves remaining. How many different final configurations are possible when you continue the game after the π‘˜ moves? It is guaranteed that the π‘˜ moves and the implied computer moves are valid. Since the answer may be large, print it modulo 1^9+7.

Two configurations are considered different if there exists a coordinate (π‘Ÿ,𝑐) which has a rook in one configuration, but not in the other or the color of the rook on the coordinate is different.


Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 940
Previous ProblemNext Problem