You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
n개의 전구가 4방향으로 빛을 쏘고, m개의 블럭은 빛을 차단한다.
전체 그리드 (H*W)에서 총 몇 칸이 빛이 도달하는지 확인.
Solution
간단한 시뮬레이션 문제.
모든 전구에서 상 하 좌 우로 빛을 쏴주면서 카운트를 해주면 된다.
Source Code
#include<iostream>
#include<vector>
#include<cstring>
#include<utility>usingnamespacestd;
vector<pair<int, int> > bulbs;
int grid[1502][1502];
int h, w, n, m;
constint direction[][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };
intmain() {
cin >> h >> w >> n >> m;
// set border to -1for (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;
}
The text was updated successfully, but these errors were encountered:
Problem link
https://atcoder.jp/contests/abc182/tasks/abc182_e
Problem Summary
n개의 전구가 4방향으로 빛을 쏘고, m개의 블럭은 빛을 차단한다.
전체 그리드 (H*W)에서 총 몇 칸이 빛이 도달하는지 확인.
Solution
간단한 시뮬레이션 문제.
모든 전구에서 상 하 좌 우로 빛을 쏴주면서 카운트를 해주면 된다.
Source Code
The text was updated successfully, but these errors were encountered: