코딩 테스트/백준

백준 - [단계별로 풀어보기 2차원 배열] 2563 색종이

devrabbit22 2026. 3. 19. 04:09

이번 문제는 문제를 정확히 이해하는 것이 중요했다.
처음에는 단순히 넓이를 구하는 수학적인 접근을 떠올렸지만, 문제를 다시 읽어보니 검은색 색종이를 도화지 위에 하나씩 붙이는 방식으로 생각할 수 있었다. 
이렇게 접근하니 복잡한 계산 없이, 각 위치를 1로 채우고 겹치는 부분을 제외하면서 자연스럽게 넓이를 구할 수 있었다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    internal class _2D_Array
    {
        static void Main(string[] args)
        {
            //백준 2563 색종이
            int paperIndex = int.Parse(Console.ReadLine());
            int[,] paperArr = new int[100,100];    //배열 사이즈 지정
            int paperSize = 0;
            for (int i = 0; i < paperIndex; i++)
            {
                string[] inputData = Console.ReadLine().Split(' ');
                int startRowPos = int.Parse(inputData[0]);
                int startColPos = int.Parse(inputData[1]);

                for (int rowPos =  startRowPos; rowPos < startRowPos + 10; rowPos++)
                {
                    for(int colPos = startColPos; colPos < startColPos + 10; colPos++)
                    {
                        //1의 값을 할당해 총 색종이의 값이 겹쳐진 색종이의 넓이이다. 단, 1의 값이 있다면 이미 색종이를 붙인 위치이므로 값 지정 X
                        if (paperArr[rowPos, colPos] == 0)
                        {
                            paperArr[rowPos, colPos] = 1;
                        }
                    }
                }
            }
            //색종이 개수 합산 = 넓이
            for(int row = 0; row < 100; row++)
            {
                for(int col = 0; col < 100; col++)
                {
                    paperSize += paperArr[row, col];
                }
            }
            Console.WriteLine(paperSize);
        }
    }
}

출력 결과

코딩 테스트를 준비하면서 문제를 정확히 이해하고, 필요한 데이터를 구분하며, 문제를 다양한 시각으로 바라보는 연습에 도움이 된 문제였다.