-
Notifications
You must be signed in to change notification settings - Fork 0
/
day12-1.cpp
54 lines (51 loc) · 1 KB
/
day12-1.cpp
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
#include <bits/stdc++.h>
using namespace std;
const int mx=2000;
int vis[mx][mx];
int dis[mx][mx];
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
// 368
int main() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int lines = 41; // line size
string s[lines];
int ansx=0,ansy=0;
for(int i=0;i<lines;i++){
cin >> s[i];
for(int j=0;j<s[i].length();j++){
if(s[i][j] == 'E'){
ansx = i;
ansy = j;
}
}
}
for(int i=0;i<2000;i++){
for(int j=0;j<2000;j++){
dis[i][j] = 1e9;
}
}
queue <pair<int,int> > q;
q.push({20,0});
dis[20][0] = 0;
int len = s[0].length();
s[20][0] = 'a';
s[ansx][ansy] = 'z';
while(!q.empty()){
int x = q.front().first;
int y = q.front().second;
q.pop();
for(int i=0;i<4;i++){
int nx = x + dx[i];
int ny = y + dy[i];
if(min(nx,ny)<0 or ny>=len or nx>=lines)continue;
if(s[x][y]+1 < s[nx][ny])continue;
if(dis[nx][ny]==1e9){
q.push({nx,ny});
dis[nx][ny] = dis[x][y]+1;
}
}
}
cout << dis[ansx][ansy] << endl;
}