Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-06-20-02.38.10
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- ll n,m,ans=0;
- char a[105][105];
- ll v[105][105];
- bool valid(ll i,ll j)
- {
- return (a[i][j]=='T');
- }
- void dfs(ll i,ll j)
- {
- if(v[i][j] || a[i][j]=='#' || a[i][j]=='T') return;
- v[i][j]=1;
- if(a[i][j]=='G') ans++;
- if(valid(i,j+1)) return;
- if(valid(i,j-1)) return;
- if(valid(i+1,j)) return;
- if(valid(i-1,j)) return;
- dfs(i,j+1);
- dfs(i,j-1);
- dfs(i+1,j);
- dfs(i-1,j);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- ll i,j,k,l;
- while(cin>>m>>n && n && m)
- {
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- {
- cin>>a[i][j];
- v[i][j]=0;
- }
- }
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- {
- if(a[i][j]=='P')
- {
- dfs(i,j);
- break;
- }
- }
- }
- cout<<ans<<nl;
- ans=0;
- }
- get_lost_idiot;
- }
- /*
- 7 4
- #######
- #P.GTG#
- #..TGG#
- #######
- 8 6
- ########
- #...GTG#
- #..PG.G#
- #...G#G#
- #..TG.G#
- ########
- */
Add Comment
Please, Sign In to add comment