시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB87664509291749.736%

문제

총 25명의 여학생들로 이루어진 여학생반은 5×5의 정사각형 격자 형태로 자리가 배치되었고, 얼마 지나지 않아 이다솜과 임도연이라는 두 학생이 두각을 나타내며 다른 학생들을 휘어잡기 시작했다. 곧 모든 여학생이 ‘이다솜파’와 ‘임도연파’의 두 파로 갈라지게 되었으며, 얼마 지나지 않아 ‘임도연파’가 세력을 확장시키며 ‘이다솜파’를 위협하기 시작했다.

위기의식을 느낀 ‘이다솜파’의 학생들은 과감히 현재의 체제를 포기하고, ‘소문난 칠공주’를 결성하는 것이 유일한 생존 수단임을 깨달았다. ‘소문난 칠공주’는 다음과 같은 규칙을 만족해야 한다.

  1. 이름이 이름인 만큼, 7명의 여학생들로 구성되어야 한다.
  2. 강한 결속력을 위해, 7명의 자리는 서로 가로나 세로로 반드시 인접해 있어야 한다.
  3. 화합과 번영을 위해, 반드시 ‘이다솜파’의 학생들로만 구성될 필요는 없다.
  4. 그러나 생존을 위해, ‘이다솜파’가 반드시 우위를 점해야 한다. 따라서 7명의 학생 중 ‘이다솜파’의 학생이 적어도 4명 이상은 반드시 포함되어 있어야 한다.

여학생반의 자리 배치도가 주어졌을 때, ‘소문난 칠공주’를 결성할 수 있는 모든 경우의 수를 구하는 프로그램을 작성하시오.

입력

'S'(이다‘솜’파의 학생을 나타냄) 또는 'Y'(임도‘연’파의 학생을 나타냄)을 값으로 갖는 5*5 행렬이 공백 없이 첫째 줄부터 다섯 줄에 걸쳐 주어진다.

출력

첫째 줄에 ‘소문난 칠공주’를 결성할 수 있는 모든 경우의 수를 출력한다.

예제 입력 1

YYYYY
SYSYS
YYYYY
YSYYS
YYYYY

예제 출력 1

2

힌트

가능한 방법은 아래와 같다.

.....    .....
SYSYS    SYSYS
....Y    .Y...
....S    .S...
.....    .....
W3sicHJvYmxlbV9pZCI6IjE5NDEiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMxOGNc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cmU6PFwvcD5cclxuXHJcbjxwcmU+XHJcbi4uLi4uICAgICAgICAgICAgICAgIC4uLi4uXHJcblNZU1lTICAgICAgICAgICAgICAgIFNZU1lTXHJcbi4uLi5ZICAgICAgIGFuZCAgICAgIC5ZLi4uXHJcbi4uLi5TICAgICAgICAgICAgICAgIC5TLi4uXHJcbi4uLi4uICAgICAgICAgICAgICAgIC4uLi4uPFwvcHJlPlxyXG5cclxuPHA+QW55IG90aGVyIHBvc3NpYmxlIGRpc3RyaWN0IHdpdGggc2V2ZW4gY293cyBoYXMgZmV3ZXIgdGhhbiA0IEplcnNleXMuPFwvcD5cclxuIiwib3JpZ2luYWwiOiIxIiwiaHRtbF90aXRsZSI6IjAiLCJwcm9ibGVtX2xhbmdfdGNvZGUiOiJFbmdsaXNoIn1d

출처

Olympiad > USA Computing Olympiad > 2004-2005 Season > USACO February 2005 Contest > Silver 2번

  • 문제의 오타를 찾은 사람: YunGoon