Connection Status:
Competition Arena > TheSimpleGame
SRM 423 · 2008-10-28 · by Vasyl[alphacom] · Simple Math
Class Name: TheSimpleGame
Return Type: int
Method Name: count
Arg Types: (int, vector<int>, vector<int>)
Problem Statement

Problem Statement

You have a n x n board and several checkers placed on it. The i-th checker is in the cell at row x[i], column y[i]. All coordinates are 1-based. There can be more than one checker in the same cell. A move consists of taking one checker and moving it one cell up, down, left or right.

You want to put each checker in one of the four corners of the board. Return the minimum number of moves necessary to achieve the goal.

Constraints

  • n will be between 1 and 100, inclusive.
  • x will contain between 1 and 50 elements, inclusive.
  • y will contain the same number of elements as x.
  • Each element of x will be between 1 and n, inclusive.
  • Each element of y will be between 1 and n, inclusive.
Examples
0)
4
{2}
{3}
Returns: 2

You need two moves to put the only checker to cell (1, 4).

1)
3
{2, 2, 1, 3}
{2, 2, 3, 1}
Returns: 4

For the first two checkers you can choose any of the four corners.

2)
7
{7, 1, 7, 7, 1, 7, 1}
{7, 1, 1, 1, 1, 7, 7}
Returns: 0

All checkers are already in the corners.

3)
3
{3, 2}
{1, 1}
Returns: 1
4)
4
{1, 1, 1}
{1, 1, 3}
Returns: 1

Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheSimpleGame with a public method int count(int n, vector<int> x, vector<int> y) · 62 test cases · 2 s / 256 MB per case

Submitting as anonymous