코딩공부/Softeer

[Softeer/C++] 나무 공격

usingsystem 2024. 11. 4. 10:31
728x90

https://softeer.ai/practice/9657

 

Softeer - 현대자동차그룹 SW인재확보플랫폼

 

softeer.ai

소스코드

#include<iostream>
#include <vector>

using namespace std;

int main(int argc, char** argv)
{
	int n, m ;
	int boardItem;
	int l1, r1;

	cin >> n >> m;

	vector<vector<int>> board (n, vector<int>(m));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> boardItem;
			board[i][j] = boardItem;
		}
	}	

for (int i = 0; i < 2; i++)
{
	cin >> l1 >> r1;

	for (int j = l1 - 1; j < r1; j++)
	{
    //처음 배치 할 때 1이라면 바로 0으로 밀어줌
		if (board[j][0] == 1)
		{
			board[j][0] = 0;
		}
     //배치 라인에 1있으면 제거
		else
		{
			board[j][0] = -1;

			for (int k = 0; k < m; k++)
			{
				if (board[j][k] == 1)
				{
					board[j][0] = 0;
					board[j][k] = 0;
					break;
				}
			}
		}
	}
}
	int answer = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (board[i][j] == 1)
				answer++;

	cout << answer;
}
728x90