Skip to content

Commit 4ac794f

Browse files
committed
[Silver IV] Title: 그래서 대회 이름 뭐로 하죠, Time: 76 ms, Memory: 43204 KB, Score: 100 point -BaekjoonHub
1 parent 11f405a commit 4ac794f

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# [Silver IV] 그래서 대회 이름 뭐로 하죠 - 27466
2+
3+
[문제 링크](https://www.acmicpc.net/problem/27466)
4+
5+
### 성능 요약
6+
7+
메모리: 43204 KB, 시간: 76 ms
8+
9+
### 분류
10+
11+
구현, 그리디 알고리즘, 문자열
12+
13+
### 제출 일자
14+
15+
2025년 5월 26일 22:38:59
16+
17+
### 문제 설명
18+
19+
<p>오늘도 운영진은 대회 이름을 정하고 있다. 몇 주째 대회 이름을 못 정하고 구글 드라이브, 지문/에디토리얼 파일, 디스코드 서버에 대회 이름으로 "대회 이름 뭐로 하죠"를 사용하고 있다.</p>
20+
21+
<p>그러던 어느 날, 그들은 KSA Automata Contest라는 이름을 떠올리게 되었고 대문자를 가져와서 KSAAC이라고 부르기로 했다. 이후 KSAAC의 발음이 "크사아악"인 사실을 알아채고 이름을 확정짓게 되었다.</p>
22+
23+
<p>운영진은 다음에 대회를 열 때는 원활한 진행을 위해 아래와 같이 대회 이름을 정하기로 했다.</p>
24+
25+
<ul>
26+
<li>먼저 협상을 통해 알파벳 대문자로 구성된 길이 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container>의 문자열 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D446 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$S$</span></mjx-container>를 정한다.</li>
27+
<li><mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"> <mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D446 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$S$</span></mjx-container>에서 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mn class="mjx-n"><mjx-c class="mjx-c30"></mjx-c></mjx-mn></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mn>0</mn></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$0$</span></mjx-container>개 이상의 문자를 지워서 대회 이름 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D447 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$T$</span></mjx-container>를 만든다.</li>
28+
<li>이때 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D447 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$T$</span></mjx-container>는 길이가 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D440 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>M</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$M$</span></mjx-container>인 <strong>운영진이 좋아하는 이름</strong>이어야 한다. <strong>운영진이 좋아하는 이름</strong>이란, 맨 뒷글자는 알파벳 자음(<code><span style="color:#e74c3c;">A</span></code>부터 <code><span style="color:#e74c3c;">Z</span></code> 중 <code><span style="color:#e74c3c;">A</span></code>, <code><span style="color:#e74c3c;">E</span></code>, <code><span style="color:#e74c3c;">I</span></code>, <code><span style="color:#e74c3c;">O</span></code>, <code><span style="color:#e74c3c;">U</span></code>를 제외한 글자들)이고, 뒤에서부터 각각 두 번째와 세 번째 글자는 <code><span style="color:#e74c3c;">A</span></code>인 문자열이다.</li>
29+
</ul>
30+
31+
<p>운영진이 또 다시 대회 이름을 정하기 위해 몇 주의 시간을 낭비하지 않도록 도와주자!</p>
32+
33+
### 입력
34+
35+
<p>첫 번째 줄에 두 정수 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container>, <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D440 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>M</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$M$</span></mjx-container>이 주어진다.</p>
36+
37+
<p>두 번째 줄에는 문자열 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D446 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$S$</span></mjx-container>가 주어진다.</p>
38+
39+
### 출력
40+
41+
<p>첫 번째 줄에 위에서 설명한 방법으로 대회 이름을 정할 수 있으면 <code><span style="color:#e74c3c;">YES</span></code>, 없으면 <code><span style="color:#e74c3c;">NO</span></code>를 출력한다.</p>
42+
43+
<p>만약 정할 수 있으면 두 번째 줄에 대회 이름으로 가능한 문자열 <mjx-container class="MathJax" jax="CHTML" style="font-size: 104.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D447 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$T$</span></mjx-container>를 출력한다.</p>
44+
45+
<p>정답이 여러 개 존재한다면 아무거나 출력해도 상관없다.</p>
46+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
3+
def main() -> None:
4+
input = sys.stdin.readline
5+
N, M = map(int, input().split())
6+
S = input().strip()
7+
8+
# 길이 자체가 불가능
9+
if M < 3 or M > N:
10+
print("NO")
11+
return
12+
13+
vowels = set("AEIOU")
14+
15+
# i 이후(자신 포함)에서 가장 왼쪽 자음 위치
16+
nxt_con = [-1] * (N + 1)
17+
for i in range(N - 1, -1, -1):
18+
nxt_con[i] = i if S[i] not in vowels else nxt_con[i + 1]
19+
20+
prev_a = -1 # 직전에 본 A 위치
21+
idx1 = idx2 = idx3 = -1 # A, A, C 세 글자의 인덱스
22+
23+
for i in range(N):
24+
if S[i] != 'A':
25+
continue
26+
27+
if prev_a != -1: # A를 두 개 연속 확보
28+
c = nxt_con[i + 1] # 그 뒤 첫 자음
29+
# 첫 번째 A가 M-3번째 자리 이후에 있어야 앞에서 M-3글자 선택 가능
30+
if c != -1 and prev_a >= M - 3:
31+
idx1, idx2, idx3 = prev_a, i, c
32+
break
33+
prev_a = i
34+
35+
if idx1 == -1: # 못 찾음
36+
print("NO")
37+
return
38+
39+
# 앞부분 M-3글자 → 무조건 첫 A 앞에서 뽑으면 순서·연속성 모두 안전
40+
prefix = S[:M - 3]
41+
T = prefix + S[idx1] + S[idx2] + S[idx3]
42+
43+
print("YES")
44+
print(T)
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)