아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Coins

시간 제한2초메모리 제한1024 MB

요약
N x N 격자에 구리 동전과 은 동전이 하나씩 놓여 있을 때, 모든 구리 동전이 은 동전보다 왼쪽과 위쪽에 오도록 최소 횟수의 교환으로 재배치한다.
난이도

보통10점 중 5점

유형
그리디, 정렬, 구현, 수학
정답자
아직 제출이 없습니다

문제

There are coins placed on squares of a N×NN \times N grid board where NN is even. There is one coin in each square. Exactly half of the coins are silver ones, the other half are copper.

The coins are placed properly if all the copper coins are in the upper left part of the board and silver coins are placed on the lower right part of the board. To be precise, if the edge of a square is a separator between different types of coins, the copper coin is either to the left or above the silver coin.

Proper placementImproper placement

Figure 1: The coins are placed properly if there are no placements as shown on the right. Black circles represent copper coins, white circles – silver ones.

You are given a set of coins placed improperly on the board. Rearrange them to get a proper placement by switching as few pairs of coins as possible.

입력

The first line of the input contains four integers – TT, NN, K_1K\_1, K_2K\_2:

  • TT – the number of the test;
  • NN – board size;
  • K_1K\_1, K_2K\_2 – values that define grading (see section Grading).

Each of the remaining NN lines contain NN integers each. They describe initial coin placement on the board. Available integers are 0 (copper coin) or 1 (silver coin).

출력

Output the board with proper placement of coins in a form of N×NN \times N board in the same format as input. Exactly one half of integers should be 0 (copper coin), the other half should be 1.

예제1

  1. 예제 1

    입력
    0 4 1 5
    0 0 1 0
    0 0 0 1
    0 1 1 1
    1 1 0 1
    
    예상 출력
    0 0 1 1
    0 0 1 1
    0 0 1 1
    0 0 1 1