Logo
(追記) (追記ここまで)

21822번 - Acowdemia III 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 512 MB35312510437.410%

문제

Bessie is a busy computer science graduate student. However, even graduate students need friends. As a result, Farmer John has opened a pasture with the explicit purpose of helping Bessie and other cows form lasting friendships.

Farmer John's pasture can be regarded as a large 2D grid of square "cells" (picture a huge chess board). Each cell is labeled with:

  • C if the cell contains a cow.
  • G if the cell contains grass.
  • . if the cell contains neither a cow nor grass.

For two distinct cows to become friends, the cows must choose to meet at a grass-covered square that is directly horizontally or vertically adjacent to both of them. During the process, they eat the grass in the grass-covered square, so future pairs of cows cannot use that square as a meeting point. The same cow may become friends with more than one other cow, but no pair of cows may meet and become friends more than once.

Farmer John is hoping that numerous pairs of cows will meet and become friends over time. Please determine the maximum number of new friendships between distinct pairs of cows that can possibly be created by the end of this experience.

입력

The first line contains $N$ and $M$ ($N,M \leq 1000$).

The next $N$ lines each contain a string of $M$ characters, describing the pasture.

출력

Count the maximum number of pairs of cows that can become friends by the end of the experience.

제한

예제 입력 1

4 5
.CGGC
.CGCG
CGCG.
.CC.C

예제 출력 1

4

힌트

If we label the cow in row $i$ and column $j$ with coordinates $(i,j),ドル then in this example there are cows at $(1,2),ドル $(1,5),ドル $(2,2),ドル $(2,4),ドル $(3,1),ドル $(3,3),ドル $(4,2),ドル $(4,3),ドル and $(4,5)$. One way for four pairs of cows to become friends is as follows:

  • The cows at $(2,2)$ and $(3,3)$ eat the grass at $(3,2)$.
  • The cows at $(2,2)$ and $(2,4)$ eat the grass at $(2,3)$.
  • The cows at $(2,4)$ and $(3,3)$ eat the grass at $(3,4)$.
  • The cows at $(2,4)$ and $(1,5)$ eat the grass at $(2,5)$.

출처

Olympiad > USA Computing Olympiad > 2020-2021 Season > USACO 2021 US Open Contest > Bronze 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /