CF961C.Chessboard

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color a__k, i, j; 1 being black and 0 being white.

Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2_n_ by 2_n_. You are allowed to move pieces but not allowed to rotate or flip them.

马格努斯决定玩一场经典的国际象棋游戏。然而,他在储物柜里看到的景象让他震惊不已!他最心爱的棋盘碎成了 4 块,每块大小均为 n×nn \times n,其中 nn 恒为奇数。更糟糕的是,某些方格的颜色错误了。第 kk 块棋盘的第 ii 行第 jj 列方格的颜色为 ak,i,ja_{k,i,j};其中 11 表示黑色,00 表示白色。

现在,马格努斯希望以最少的重涂方格数量,将这些碎片重新着色,使得拼合后的整体构成一个合法的国际象棋棋盘。在合法棋盘中,每个方格的颜色均与其所有(上下左右)相邻方格的颜色不同。最终棋盘尺寸应为 2n×2n2n \times 2n。你可以任意移动这 4 块碎片的位置,但不允许旋转或翻转它们。

输入格式

The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board.

Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.

第一行包含一个奇数 $ n (( 1 \leq n \leq 100 $)——表示棋盘每一块的尺寸。

随后是 4 个段落,每个段落描述棋盘的一块。每个段落由 $ n $ 行、每行 $ n $ 个字符组成;其中第 $ i $ 行的第 $ j $ 个字符为 1 表示该方格初始为黑色,为 0 表示非黑色。各段落之间以空行分隔。

输出格式

Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.

输出一个数字——Magnus 需要重涂的最少方格数,以得到一个有效的棋盘。

输入输出样例

  • 输入#1

    1
    0
    
    0
    
    1
    
    0

    输出#1

    1
  • 输入#2

    3
    101
    010
    101
    
    101
    000
    101
    
    010
    101
    011
    
    010
    101
    010

    输出#2

    2

输入解题思路,AI测评打分。不知道怎么写?

首页