슈콩

[SWEA] 격자판 칠하기 본문

Algorithms/SWEA

[SWEA] 격자판 칠하기

shukong 2025. 11. 14. 18:15

 

 

[문제]

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

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	static int n,m;
	static char[][] map;
	
	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());
			n = Integer.parseInt(st.nextToken());
			m = Integer.parseInt(st.nextToken());
			map = new char[n][m];
			for(int i=0;i<n;i++) {
				map[i] = br.readLine().toCharArray();
			}
			if(check('#','.') || check('.','#')) {
				System.out.println("#"+tc+" possible");
			}
			else System.out.println("#"+tc+" impossible");
		}
	}
	private static boolean check(char a,char b) {
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if((i+j)%2==0 && map[i][j]==a) {
					return false;
				}
				if((i+j)%2==1 && map[i][j]==b) {
					return false;
				}
			}
		}
		return true;
	}
}

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

[SWEA] 준환이의 운동관리  (0) 2025.11.14
[SWEA] 정사각형 판정  (0) 2025.11.14
[SWEA] 식료품 가게  (0) 2025.11.14
[SWEA] 5일차 - GNS  (0) 2025.11.14
[SWEA] 삼성시의 버스 노선  (0) 2025.11.14