-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday21.cpp
94 lines (82 loc) · 1.72 KB
/
day21.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
lengli_QAQ
Hope there are no bugs!!!
*/
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb emplace_back
using namespace std;
//--------------------------------
template<typename T> void printvt(vector<T> &a){
for(auto x:a) cout<<x<<" ";cout<<endl;
};
template<typename T> void printay(T a[],int l,int r){
for(int i=l;i<=r;i++) cout<<a[i]<<" ";cout<<endl;
};
//--------------------------------
typedef pair<int,int> PII;
typedef long long LL;
const int N=210;
vector<string> g;
int n,m,sx,sy;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
bool st[N][N][100];
set<PII> bfs(int tt){
set<PII> res;
vector<PII> ans;
queue<array<int,3>> q;
q.push({sx,sy,1});
while(q.size()){
auto t=q.front();
q.pop();
if(t[2]>tt) continue;
if(t[2]==tt){
ans.pb(t[0],t[1]);
continue;
}
if(st[t[0]][t[1]][t[2]]) continue;
st[t[0]][t[1]][t[2]]=1;
for(int i=0;i<4;i++){
int nx=t[0]+dx[i],ny=t[1]+dy[i];
if(nx<0 or nx>=n or ny<0 or ny>=m or g[nx][ny]=='#') continue;
q.push({nx,ny,t[2]+1});
}
}
for(auto [x,y]:ans){
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(nx<0 or nx>=n or ny<0 or ny>=m or g[nx][ny]=='#') continue;
res.insert({nx,ny});
}
}
return res;
}
void solve(){
string s;
while(cin>>s) g.pb(s);
n=g.size(),m=g[0].size();
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(g[i][j]=='S') g[i][j]='.',sx=i,sy=j;
}
int tot=124;
set<int> k={tot};
for(int i=tot-1,j=1;j>=1;i--,j++){
int r=i-j;
if(r<1) break;
k.insert(r);
}
cout<<k.size()<<endl;
set<PII> res=bfs(64);
cout<<res.size()<<endl;
}
signed main(){
fastio;
int T;
T=1;
while(T--) solve();
return 0;
}