내용으로 건너뛰기
테페리넷
사용자 도구
등록
로그인
사이트 도구
검색
도구
문서 보기
Fold/unfold all
역링크
미디어 관리자
사이트맵
등록
로그인
>
미디어 관리자
사이트맵
현재 위치:
테페리넷
»
Problem Solving
»
문제
»
백준 온라인 저지 (BOJ)
»
제이크와 케이크
ps:problems:boj:16440
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== 제이크와 케이크 ====== ===== 풀이 ===== * [[ps:tutorial:Necklace Splitting Problem]]의 특수한 경우 * 최대 2번의 칼질로 원하는 분할이 가능하다. 분할 위치는 [[ps:tutorial:슬라이딩 윈도우]]로 찾으면 된다. 시간복잡도는 O(n) ===== 코드 ===== <dkpr py> """Solution code for "BOJ 16440. 제이크와 케이크". - Problem link: https://www.acmicpc.net/problem/16440 - Solution link: http://www.teferi.net/ps/problems/boj/16440 Tags: [sliding window] """ def main(): N = int(input()) cake = input() target_s_count = N // 4 s_count = cake[: N // 2].count('s') if s_count == target_s_count: print('1') print(N // 2) return for rem, add, beg in zip(cake, cake[N // 2 :], range(1, N)): if rem == 's': s_count -= 1 if add == 's': s_count += 1 if s_count == target_s_count: print('2') print(beg, beg + N // 2) break if __name__ == '__main__': main() </dkpr> {{tag>BOJ ps:problems:boj:플래티넘_5}}
ps/problems/boj/16440.txt
· 마지막으로 수정됨: 2024/12/01 04:19 저자
teferi
문서 도구
문서 보기
역링크
Fold/unfold all
맨 위로