Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 그래프
- Unreal Engine 5
- 정렬
- 그리디 알고리즘
- 우선순위 큐
- 재귀
- 알고리즘
- DFS
- Team Fortress 2
- VR
- 시뮬레이션
- 유니온 파인드
- 구현
- XR Interaction Toolkit
- 누적 합
- c++
- 다익스트라
- 백트래킹
- 자료구조
- 투 포인터
- 수학
- 브루트포스
- BFS
- 문자열
- 트리
- ue5
- 스택
- 유니티
- 다이나믹 프로그래밍
- 백준
Archives
- Today
- Total
1일1알
백준 22352번 항체 인식 C++ 본문
https://www.acmicpc.net/problem/22352
22352번: 항체 인식
첫 번째 줄에는 SP 촬영 결과의 크기를 의미하는 두 정수 $N$과 $M$이 주어진다. ($1 \le N, M \le 30$) 이는 촬영 결과가 세로로 $N$칸, 가로로 $M$칸 크기의 격자라는 것을 의미한다. 다음 $N$개의 줄에는
www.acmicpc.net
백신 이전 결과에서 이어진 부분의 영역은 백신 이후 영역에서 백신 이전 결과와는 달라도 되지만 모두 같은 값으로 채워져야 하고 나머지 부분은 백신 이전 결과와 백신 이후 결과가 모두 같은 값이어야 한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
int dRow[4] = { -1,0,1,0 };
int dCol[4] = { 0,1,0,-1 };
vector<vector<int>> beforeBoard;
vector<vector<int>> afterBoard;
vector<vector<bool>> bBFound;
vector<vector<bool>> found;
void RefreshFound() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
found[i][j] = false;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
beforeBoard = vector<vector<int>>(n, vector<int>(m));
afterBoard = vector<vector<int>>(n, vector<int>(m));
bBFound = vector<vector<bool>>(n, vector<bool>(m, false));
found = vector<vector<bool>>(n, vector<bool>(m, false));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> beforeBoard[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> afterBoard[i][j];
}
}
bool ans = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (bBFound[i][j]) continue;
RefreshFound();
int val = beforeBoard[i][j];
vector<pair<int, int>> v;
queue<pair<int, int>> q;
bBFound[i][j] = true;
found[i][j] = true;
q.push({ i,j });
v.push_back({ i,j });
while (!q.empty()) {
auto curr = q.front();
q.pop();
for (int k = 0; k < 4; k++) {
int nextRow = curr.first + dRow[k];
int nextCol = curr.second + dCol[k];
if (nextRow < 0 || nextRow >= n) continue;
if (nextCol < 0 || nextCol >= m) continue;
if (found[nextRow][nextCol]) continue;
if (beforeBoard[nextRow][nextCol] != val) continue;
found[nextRow][nextCol] = true;
bBFound[nextRow][nextCol] = true;
q.push({ nextRow,nextCol });
v.push_back({ nextRow,nextCol });
}
}
set<int> s;
for (auto a : v) {
s.insert(afterBoard[a.first][a.second]);
}
if (s.size() != 1) continue;
bool isAns = true;
for (int k = 0; k < n; k++) {
for (int y = 0; y < m; y++) {
if (found[k][y]) continue;
if (beforeBoard[k][y] == afterBoard[k][y]) continue;
isAns = false;
}
}
if (isAns) ans = true;
}
}
if (ans) cout << "YES";
else cout << "NO";
}
'알고리즘' 카테고리의 다른 글
백준 1774번 우주신과의 교감 C++ (0) | 2022.12.10 |
---|---|
백준 1613번 역사 C++ (0) | 2022.12.09 |
백준 5212번 지구 온난화 C++ (0) | 2022.12.07 |
백준 14248번 점프 점프 C++ (0) | 2022.12.06 |
백준 12018번 Yonsei TOTO C++ (1) | 2022.12.05 |