300x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- PYTHON
- AI
- 순열
- 그래프
- 코딩 테스트
- 네트워크
- 킥스타트
- 딥러닝
- 브루트포스
- 알고리즘
- 코딩테스트
- BFS
- DFS
- 프로그래머스
- OS
- 동적프로그래밍
- 구글 킥스타트
- 코딩
- 파이썬
- 리눅스
- 동적 프로그래밍
- 백준
- linux
- google coding competition
- 프로그래밍
- kick start
- dp
- CSS
- nlp
- 운영체제
Archives
- Today
- Total
오뚝이개발자
[Google Kick Start] 2021 구글 킥스타트 Round G Dogs and Cats 풀이 본문
코딩 테스트/Google Kick Start
[Google Kick Start] 2021 구글 킥스타트 Round G Dogs and Cats 풀이
땅어 2021. 11. 18. 22:12728x90
300x250
문제
https://codingcompetitions.withgoogle.com/kickstart/round/00000000004362d6/00000000008b3771
Kick Start - Google’s Coding Competitions
Hone your coding skills with algorithmic puzzles meant for students and those new to coding competitions. Participate in one round or join them all.
codingcompetitions.withgoogle.com
나의 풀이
간단한 구현 문제이다. NO를 출력하는 경우는 다음의 두 가지이다.
- S[i]=='C' and C==0 and i<dog_max (dog_max는 입력에서 D가 마지막으로 등장하는 index이다.)
- S[i]=='D' and D==0
위의 두 가지 경우 이외에는 YES를 출력해주면 된다. 변수 C와 D의 값은 만날 때마다 적절히 업데이트 해주면 된다.
코드
# https://codingcompetitions.withgoogle.com/kickstart/round/00000000004362d6/00000000008b3771
T = int(input())
for t in range(T):
N, D, C, M = list(map(int, input().split()))
S = input()
dog_max = -1 # max index of 'D'
for i in range(N-1, -1, -1):
if S[i] =='D':
dog_max = i
break
if dog_max == -1:
print(f"Case #{t+1}: YES")
continue
ans = "YES"
for i in range(N):
# two NO case
if S[i]=='C' and C==0 and i<dog_max:
ans = 'NO'
break
elif S[i]=='D' and D==0:
ans = 'NO'
break
# update
if S[i] == 'C':
C -= 1
elif S[i] == 'D':
D -= 1
C += M
print(f"Case #{t+1}: " + ans)
728x90
300x250
'코딩 테스트 > Google Kick Start' 카테고리의 다른 글
[Google Kick Start] 2021 구글 킥스타트 Round H Painter 풀이 (0) | 2021.11.27 |
---|---|
[Google Kick Start] 2021 구글 킥스타트 Round H Transform the string 풀이 (0) | 2021.11.20 |
[Google Kick Start] 2021 구글 킥스타트 Round E Suffled Anagrams 풀이 (0) | 2021.11.14 |
[Google Kick Start] 2021 구글 킥스타트 Round D Arithmetic Square 풀이 (0) | 2021.11.14 |
[Google Kick Start] 2021 구글 킥스타트 Round B Increasing Substring 풀이 (0) | 2021.11.06 |
Comments