Vandalized Chessboard
Time limit1sMemory limit128 MB
Given a board size and a blackened row, column, and two diagonals, compute the number of distinct blackened cells and how many should be repainted grey versus white based on the checkerboard color rule.
- Level
Medium6 of 10
- Topics
- Math, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
A village hall has a white-and-grey chessboard of size N x N painted on it.
Rows and columns are numbered from 1 to N. If a cell has column x and row y, the bottom-left cell is (1, 1), and that cell is grey. Adjacent cells have different colors.
There are also two types of diagonals, each numbered from 1 to 2N - 1. A type 1 diagonal with number d contains exactly the cells with x + y - 1 = d. A type 2 diagonal with number d contains exactly the cells with x - y + N = d.
One night, someone painted black every cell in one row, one column, one type 1 diagonal, and one type 2 diagonal.
To restore the chessboard, every blackened cell must be repainted either grey or white. Find the total number of distinct cells that must be repainted, and how many of them must be painted grey and white.
Input
The first line contains the integer N, the side length of the chessboard. (1 <= N <= 10 000 000)
The second line contains four integers r c d1 d2: the painted row number, column number, type 1 diagonal number, and type 2 diagonal number, in that order.
Output
On the first line, output the total number of distinct cells that must be repainted.
On the second line, output how many of those cells must be painted grey and how many must be painted white, in that order.


