oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

reversi Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

reversi.html

Problem Description

The holidays have just ended so Jiahai is bored. So he decides to play reversi against himself to relief himself of his boredom while appearing interested in the lesson at the same time. It went very well for a day, until Jiahai realised that since Jiahai's playing against himself, Jiahai would know all the moves Jiahai would play before Jiahai moves. To counter this problem, he's asking your help to write a program to play against Jiahai. The program should always play a piece such that the resultant board immediately after its move would have the most number of its pieces.

Help Jiahai write a program which would find the move it could play which would give the highest number of the its remaining pieces!

Input

The first line of input will consist of 1 integer, N. N denotes the length of the square board. N will be a positive integer not exceeding 20.

The following N lines will consist of a string of length N. Each character in the string denotes the piece at that position. '.' refer to a blank spot, 'J' refer to Jiahai's pieces, and 'P' refer to the program's own pieces

Output

print one number, the number of remaining pieces belonging to the program after the program makes its move.

Sample Input

5
PPP..
.JJP.
PJ.JP
.PJJ.
..P..

Sample Output

14

Explanation of Sample Output

putting the piece at the center of the board would flip 5 surrounding pieces. resulting in this: (using a star to denote the piece which the program just placed)

PPP..
.PPP.
PP*PP
.PPJ.
..P..
an answer which would come close would flip 4 pieces, resulting in this:
PPP..
.JPP.
PJ.PP
.PPP*
..P..
do note that the piece which the program just played would also count towards the final answer.

Tags

Ad Hoc, Syntax

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
1100201s64MBAverage
2011s64MBAverage

Judge Compile Command

g++-8 ans.cpp -o reversi -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.