Covering Chessboard
Practice
4 (14 votes)
Graphs
Medium
Problem
85% Success 407 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You have an n by m grid. Each grid square has a certain value associated with it. This is given by the numbers vi,j.

You can capture grid squares in two different ways.

  1. You can directly capture a grid square. This costs ci,j.
  2. You can indirectly capture a grid square. You can only do this if we have already captured all of this squares neighbors. This costs bi,jci,j.
Two squares are neighbors if they share an edge.

Your score is the sum of values you have captured minus the cost it took to capture those squares. Return the maximum possible score you can achieve.

Input format:

The first line of input will contain two integers n, m.

The next n lines of input will contain m space separated integers each. The j-th number on the i-th line denotes vi,j.

The next n lines of input will contain m space separated integers each. The j-th number on the i-th line denotes bi,j.

The next n lines of input will contain m space separated integers each. The j-th number on the i-th line denotes ci,j.

Output format:

Print a single integer, the answer to the problem.

Constraints

For all subtasks:
0 ≤ vi,j ≤ 100,000
0 ≤ bi,jci,j ≤ 100,000
1 ≤ n, m

Subtask 1 (45 pts):
n, m ≤ 3

Subtask 2 (35 pts):
n, m ≤ 7

Subtask 3 (20 pts):
n, m ≤ 25

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
4 votes
Tags:
AlgorithmsApprovedFlowGraphsMedium