Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- IPv4 주소체계
- 원형 연결 구조 연결된 큐
- c언어 괄호검사
- 프로그래머스 푸드 파이트 대회
- 주기억장치
- 알고리즘 조건
- 문자형 배열
- auto 키워드
- 문제해결 단계
- r-value참조자
- 범위 기반 for문
- 회전 및 자리 이동 연산
- 입출력 관리자
- C언어 계산기 프로그램
- const화
- 백준 파이썬
- string유형
- 논리 연산
- l-value참조자
- LAN의 분류
- 값/참조/주소에 의한 전달
- 유형 변환
- 프로그래머스 배열만들기4
- C언어 덱
- C언어 스택 연산
- 운영체제 기능
- 네트워크 결합
- 괄호 검사 프로그램
- const l-value참조자
- getline()함수
Archives
- Today
- Total
chyam
[백준] 12891번, python - DAN 비밀번호 본문

https://www.acmicpc.net/problem/12891
s, p = map(int, input().split())
st = input()
st_cnt = list(map(int, input().split())) # [A, C, G, T] 최소 요구 개수
res = 0
# 현재 윈도우 문자 개수
cur_cnt = [0, 0, 0, 0]
# 문자 -> 인덱스
idx = {"A": 0, "C": 1, "G": 2, "T": 3}
# 초기 윈도우 채우기
for i in range(p):
cur_cnt[idx[st[i]]] += 1
# 조건 만족 확인 함수
def check():
for i in range(4):
if cur_cnt[i] < st_cnt[i]:
return False
return True
if check():
res += 1
# 슬라이딩 윈도우
for i in range(p, s):
# 새로 들어온 문자
cur_cnt[idx[st[i]]] += 1
# 빠져나간 문자
cur_cnt[idx[st[i - p]]] -= 1
if check():
res += 1
print(res)
# 시간초과 걸린코드. count를 사용해서 시간초과 발생.
s, p = map(int,input().split())
st = input()
st_cnt = list(map(int,input().split()))
res = 0
start, end = 0, p
while end <= s:
cnt = [st[start:end].count("A"),st[start:end].count("C"),st[start:end].count("G"),st[start:end].count("T")]
if all(cnt[i] >= st_cnt[i] for i in range(4)):
res += 1
start += 1
end += 1
print(res)'백준' 카테고리의 다른 글
| [백준] 5464번,python - 주차장 (0) | 2025.09.09 |
|---|---|
| [백준] - 1874번, python - 스택 수열 (0) | 2025.09.08 |
| [백준] 1253,python - 좋다 (0) | 2025.09.05 |
| [백준] - 11660,python - 구간 합 구하기 5 (0) | 2025.09.04 |
| [백준] 26070번, python - 곰곰이와 학식 (2) | 2025.09.03 |
