Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABC_182_E - Akari #16

Open
zeikar opened this issue Oct 4, 2021 · 0 comments
Open

ABC_182_E - Akari #16

zeikar opened this issue Oct 4, 2021 · 0 comments
Assignees
Labels
study Study

Comments

@zeikar
Copy link
Owner

zeikar commented Oct 4, 2021

Problem link

https://atcoder.jp/contests/abc182/tasks/abc182_e

Problem Summary

n개의 전구가 4방향으로 빛을 쏘고, m개의 블럭은 빛을 차단한다.
전체 그리드 (H*W)에서 총 몇 칸이 빛이 도달하는지 확인.

Solution

간단한 시뮬레이션 문제.
모든 전구에서 상 하 좌 우로 빛을 쏴주면서 카운트를 해주면 된다.

Source Code

#include <iostream>
#include <vector>
#include <cstring>
#include <utility>
using namespace std;

vector<pair<int, int> > bulbs;
int grid[1502][1502];
int h, w, n, m;

const int direction[][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };

int main() {
	cin >> h >> w >> n >> m;

	// set border to -1
	for (int i = 0; i <= h; i++)
	{
		grid[i][0] = -1;
		grid[i][w + 1] = -1;
	}
	for (int i = 0; i <= w; i++)
	{
		grid[0][i] = -1;
		grid[h + 1][i] = -1;
	}

	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;

		grid[a][b] = 1;
		bulbs.push_back(make_pair(a, b));
	}

	for (int i = 0; i < m; i++)
	{
		int c, d;
		cin >> c >> d;

		grid[c][d] = -1;
	}

	int ans = n;

	for (int i = 0; i < n; i++)
	{
		int a = bulbs[i].first;
		int b = bulbs[i].second;

		for (int d = 0; d < 4; d++)
		{
			int x = a, y = b;
			int cnt = 1;

			while (true)
			{
				int nx = x + direction[d][0] * cnt;
				int ny = y + direction[d][1] * cnt;

				if (grid[nx][ny] == -1 || grid[nx][ny] == 1)
				{
					break;
				}

				if (grid[nx][ny] == 0)
				{
					ans++;
				}
				grid[nx][ny] = 2;
				cnt++;
			}
		}
	}

	cout << ans << endl;
}
@zeikar zeikar added the study Study label Oct 4, 2021
@zeikar zeikar self-assigned this Oct 4, 2021
zeikar added a commit that referenced this issue Oct 4, 2021
@zeikar zeikar changed the title [Study] ABC_182_E [Study] ABC_182_E - Akari Oct 4, 2021
zeikar added a commit that referenced this issue Oct 10, 2021
@zeikar zeikar changed the title [Study] ABC_182_E - Akari ABC_182_E - Akari Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
study Study
Projects
None yet
Development

No branches or pull requests

1 participant