-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28450.cpp
More file actions
73 lines (56 loc) · 996 Bytes
/
28450.cpp
File metadata and controls
73 lines (56 loc) · 996 Bytes
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int INF= 1e9;
typedef pair<int,int> pii;
int xn[2] = {1,0};
int yn[2] = {0,1};
struct Node{
int x;
int y;
int v;
Node(int x, int y, int v){
this->x = x;
this->y = y;
this->v = v;
}
};
int main(){
int n , m ;
cin >> n >> m;
int arr[n][m];
for(int i=0; i< n; i++){
for(int j=0;j<m;j++){
int x;
cin >> x;
arr[i][j]= x;
}
}
int p;
cin >> p;
Node loc = Node(0,0,p);
queue<pii> q;
q.push(loc);
int result= -1;
while(true){
int x = q.front().x;
int y = q.front().y;
int p = q.front().v;
q.pop();
if(x== n-1 && y== m-1){
if(p> result)
result = p;
continue;
}
for(int i=0; i<2;i++){
int next_x = x+xn[i];
int next_y = y+yn[i];
if(next_x<0 || next_x>= n || next_y <0 || next>= m || arr[next_x][next_y]>= p ) continue;
loc = Node(next_x,next_y,p-arr[next_x][next_y]);
q.push(loc);
}
}
return 0;
}