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

Moo Operations

Silver V 실버 V
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Because Bessie is bored of playing with her usual text string where the only
characters are 'C,' 'O,' and 'W,' Farmer John gave her \(Q\) new strings
(\(1 \leq Q \leq 100\)), where the only characters are 'M' and 'O.' Bessie's
favorite word out of the characters 'M' and 'O' is obviously "MOO," so she wants
to turn each of the \(Q\) strings into "MOO" using the following operations:

  1. Replace either the first or last character with its opposite (so that 'M' becomes 'O' and 'O' becomes 'M').
  2. Delete either the first or last character.

Unfortunately, Bessie is lazy and does not want to perform more operations than
absolutely necessary. For each string, please help her determine the minimum
number of operations necessary to form "MOO" or output \(-1\) if this is
impossible.

Problem credits: Aryansh Shrivastava

제약

SCORING

  • Inputs 2-4: Every string has length at most \(3\).
  • Inputs 5-11: No additional constraints.

Problem credits: Aryansh Shrivastava

입력 형식

The first line of input contains the value of \(Q\).

The next \(Q\) lines of input each consist of a string, each of its characters
either 'M' or 'O'. Each string has at least 1 and at most 100 characters.

출력 형식

Output the answer for each input string on a separate line.

예제 1
입력
3
MOMMOM
MMO
MOO
출력
4
-1
0
설명

A sequence of \(4\) operations transforming the first string into "MOO" is as
follows:

Replace the last character with O (operation 1)
Delete the first character (operation 2)
Delete the first character (operation 2)
Delete the first character (operation 2)

The second string cannot be transformed into "MOO." The third string is already
"MOO," so no operations need to be performed.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > January > Bronze

태그

평가 및 의견

Moo Operations

개요
출제자 난이도 Silver V 실버 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Moo Operations

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