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
- Security
- 민겸수
- 백준
- 백준 1253번
- 언리얼 커스텀 플러그인
- 1253번
- 데이터베이스 배움터
- oracle
- 실습
- 트랜잭션 관리
- 5639
- 1967번
- C++
- 오손데이터읽기
- OS
- 셰그먼트트리
- Unreal
- 언리얼 플러그인
- Linux
- SQL
- command not found
- 2단계로킹
- 의미와 무의미의 경계에서
- UnrealMP
- 1759번
- 비재귀셰그먼트
- UActor
- objtofbx
- hackerank
- FBX
Archives
- Today
- Total
fatalite
미로 만들기 - 2665번 백준 본문
문제
문제 난이도 : 골드 4
문제 분류 : 다익스트라
문제 코드
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <memory.h>
using namespace std;
int Distance[3000];
vector<pair<int, int>> Edges[3000];
const int MYINTMAX{ 2140000000 };
bool Visited[3000];
void Init()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout.tie(NULL);
}
void Dijkstra(int s, int e) {
for (int i = 0; i < 3000; i++) {
Distance[i] = MYINTMAX;
}
Distance[s] = 0;
priority_queue<pair<int, int>> PQ;
PQ.push({ 0,0 });
while (!PQ.empty()) {
int CurDist = - PQ.top().first;
int CurIndex = PQ.top().second;
PQ.pop();
if (Visited[CurIndex] == true) continue;
Visited[CurIndex] = true;
for (int i = 0; i < Edges[CurIndex].size(); i++) {
int NextDist = Edges[CurIndex][i].first;
int NextIndex = Edges[CurIndex][i].second;
if (Distance[NextIndex] >= NextDist + CurDist) {
Distance[NextIndex] = NextDist + CurDist;
PQ.push({ -Distance[NextIndex], NextIndex });
}
}
}
}
int main()
{
Init();
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < n; j++) {
if (s[j] == '0') {
if (i > 0) {
Edges[i * n + j].push_back({ 1, (i-1) * n + j });
}
if (j > 0) {
Edges[i * n + j].push_back({ 1, i * n + (j - 1) });
}
if (i < n - 1) {
Edges[i * n + j].push_back({1, (i + 1)* (n) + j });
}
if (j < n - 1) {
Edges[i * n + j].push_back({ 1, i * n + (j + 1) });
}
}
else {
if (i > 0) {
Edges[i * n + j].push_back({ 0, (i-1) * (n) + j });
}
if (j > 0) {
Edges[i * n + j].push_back({ 0, i * n + (j - 1) });
}
if (i < n - 1) {
Edges[i * n + j].push_back({ 0, (i +1)* (n) + j });
}
if (j < n - 1) {
Edges[i * n + j].push_back({ 0, i * n + (j + 1) });
}
}
}
}
Dijkstra(0, n * n);
cout << Distance[n * n - 1];
}
'코딩 인터뷰 > Graph Basic' 카테고리의 다른 글
줄 세우기 - 2252번 백준 (1) | 2023.10.03 |
---|---|
네트워크 연결 - 1922번 백준 (0) | 2023.09.26 |
별자리 만들기 - 4386번 백준 (0) | 2023.09.26 |
녹색 옷 입은 애가 젤다지? - 4485번 백준 (0) | 2023.09.25 |
알고스팟 - 1261번 백준 (0) | 2023.09.25 |