RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00724

Čokolada

설명

Luka loves chocolate. He is very excited to eat a large chocolate bar made of \(n\)
rows and \(m\) columns he got for his birthday. The chocolate consists of black and
white squares of chocolate. However, Luka doesn’t really like white chocolate and
would only like to eat the black squares.
Before he starts eating, Luka will cut the chocolate. He will make a number
of vertical and/or horizontal cuts in between the rows and the columns of the
chocolate. A vertical cut goes from the top edge of the chocolate to the bottom
edge, while a horizontal cut goes from the left edge to the right edge. After making
the cuts, Luka will obtain several rectangular pieces of chocolate.
Since Luka will only eat the black parts of the chocolate, he wants to completely seperate the black squares
from the white squares. This means that every resulting piece must consist entirely of black chocolate or
entirely of white chocolate.
Luka would rather start eating as soon as possible instead of wasting time cutting so he asks you to help
him determine the minimum number of cuts required to separate the black squares from the white squares.
Slika 1: This is how the chocolate from the first example should be cut in order to separate the black
parts from the white parts with minimum number of cuts

제약
입력 형식

In the first line, there are two natural numbers \(n\) and \(m\) (\(1 \le n\), \(m \le 200\)), representing the number of
rows and columns of the chocolate.
Each of the following \(n\) lines contains \(m\) characters, each of which is either 0 or 1. The character 0 denotes
a white square, and 1 denotes a black square.

출력 형식

In the first and only line, output a single number - the minimum number of cuts required to separate the
black squares from the white squares.

서브태스크
서브태스크점수설명

1

5점

The chocolate is a chessboard, i.e. the square in the \(i-th\) row and \(j-th\) column is white if \(i + j\) is an even number, and black if it is odd.

2

11점

\(n = 1\)

3

11점

Exactly one square is black.

4

23점

No additional constraints.

예제 1
입력
4 7
0000000
0111000
0111100
0000000
출력
6
예제 2
입력
4 5
00000
01100
01100
00000
출력
4
예제 3
입력
4 4
0101
1010
0101
1010
출력
6
설명

Clarification of the first example:
Explained in the drawing.
Clarification of the second example:
Luka should make a cut between the first and second row, third and fourth row, first and second column,
and third and fourth column.
Clarification of the third example:
Luka should make a cut between every two adjacent rows and columns - a total of 6 cuts.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 6

평가 및 의견

Čokolada

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Čokolada

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8