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

Find and Replace

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

의견: 0

설명

Bessie is using the latest and greatest innovation in text-editing software,
miV! She starts with an input string consisting solely of upper and lowercase
English letters and wishes to transform it into some output string. With just
one keystroke, miV allows her to replace all occurrences of one English letter
\(c_1\) in the string with another English letter \(c_2\). For example, given the
string \(\texttt{aAbBa}\), if Bessie selects \(c_1\) as 'a' and \(c_2\) as 'B', the given string transforms into
\(\texttt{BAbBB}\).

Bessie is a busy cow, so for each of \(T\) (\(1\le T\le 10\)) independent test
cases, output the minimum number of keystrokes required to transform her input
string into her desired output string.

Problem credits: Benjamin Qi

제약

SCORING

  • Inputs 2-6: Every string has a length at most \(50\).
  • Inputs 7-9: All strings consist only of lowercase letters '\(\texttt{a}\)' through '\(\texttt{e}\)'
  • Inputs 10-15: No additional constraints.

Problem credits: Benjamin Qi

입력 형식

The first line contains \(T\), the number of independent test cases.

The following \(T\) pairs of lines contain an input and output string of equal
length. All characters are upper or lowercase English letters (either A through
Z or a through z). The sum of the lengths of all strings does not exceed \(10^5\).

출력 형식

For each test case, output the minimum number of keystrokes required to change
the input string into the output string, or \(-1\) if it is impossible to do so.

예제 1
입력
4
abc
abc
BBC
ABC
abc
bbc
ABCD
BACD
출력
0
-1
1
3
설명

The first input string is the same as its output string, so no keystrokes are
required.

The second input string cannot be changed into its output string because Bessie
cannot change one '\(\texttt{B}\)' to '\(\texttt{A}\)' while keeping the other as
'\(\texttt{B}\)'.

The third input string can be changed into its output string by changing
'\(\texttt{a}\)' to '\(\texttt{b}\)'.

The last input string can be changed into its output string like so:
\(\texttt{ABCD} \rightarrow \texttt{EBCD} \rightarrow \texttt{EACD} \rightarrow \texttt{BACD}\).

문제 정보

riseoj 작성

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

태그

평가 및 의견

Find and Replace

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

Log in to rate problems.

개별 의견

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

풀이 제출

Find and Replace

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