슈콩

[SWEA] 부먹왕국의 차원 관문 본문

Algorithms/SWEA

[SWEA] 부먹왕국의 차원 관문

shukong 2025. 11. 20. 23:18

 

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWuSgKpqmooDFASy

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int d = Integer.parseInt(st.nextToken());
			int[] kingdom = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				kingdom[i] = Integer.parseInt(st.nextToken());
			}
			int result = 0;
			int idx = -1;
			out:
			while(idx<n-d) {
				for(int i=d;i>0;i--) {
					if(kingdom[idx+i]==1) {
						idx += i;
						continue out;
					}
				}
				result++;
				idx += d;
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 두 수의 덧셈  (0) 2025.11.21
[SWEA] 다솔이의 월급 상자  (0) 2025.11.21
[SWEA] 순열1  (0) 2025.11.20
[SWEA] 과자 분배  (0) 2025.11.20
[SWEA] 집합 비교  (0) 2025.11.20