-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ4588.cpp
More file actions
59 lines (50 loc) · 1 KB
/
BOJ4588.cpp
File metadata and controls
59 lines (50 loc) · 1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
int n;
int arr[150][150];
int dy[4] = { 1,0,-1,0 }, dx[4] = { 0,1,0,-1 };
struct st {
int value;
pair<int, int> pos;
};
struct cmp {
bool operator()(st& u, st& v) {
return u.value > v.value;
}
};
priority_queue<st, vector<st>, cmp> pq;
int main()
{
int cur = 0;
scanf("%d", &n);
while (n != 0) {
cur++;
fill_n(&arr[0][0], 150 * 150, -1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &arr[i][j]);
st s = { arr[1][1],{1,1 } };
pq.push(s);
arr[1][1] = -1;
while (!pq.empty())
{
st p = pq.top();
if (p.pos.first == n && p.pos.second == n) {
printf("Problem %d: %d\n", cur, p.value);
}
//printf("%d\n", p.value);
for (int i = 0; i < 4; i++)
{
int ny = p.pos.first + dy[i], nx = p.pos.second + dx[i];
if (arr[ny][nx] == -1)
continue;
pq.push({ p.value + arr[ny][nx], { ny,nx } });
arr[ny][nx] = -1;
}
pq.pop();
}
scanf("%d", &n);
}
}