Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define REP(i,n) for(int i = 0; i < n; i++)
- #define REPP(i, a, n) for(int i = a; i < n; i++)
- #define RI(n) for(int i = 0; i < n; i++)
- #define IN(n) int n; cin>>n;
- #define OUT(x) cout<<x<<'\n';
- #define DBG(x) cout<<#x<<" = "<<x<<'\n';
- #define VI vector<int>
- #define ENDL cout<<'\n';
- #define STOP system("pause");
- #define pb push_back
- #define mp make_pair
- int inf = 1e18 * 2;
- main(){
- //ios_base::sync_with_stdio(false);
- //cin.tie(0);
- //cout.tie(0);
- IN(n)
- IN(m)
- n+=2;
- m+=2;
- vector<vector<bool>>home(n, vector<bool>(m, false));
- vector<vector<bool>>water(n, vector<bool>(m, false));
- REP(i, n - 2)
- REP(j, m - 2){
- char c;
- cin>>c;
- if(c!='.')home[i + 1][j + 1] = true;
- }
- REP(i, n - 2)
- REP(j, m - 2){
- char c;
- cin>>c;
- if(c!='.')water[i + 1][j + 1] = true;
- }
- //DBG("11")
- int ans = 0;
- for(int i = -n; i <= n; i++){
- //DBG(i)
- for(int j = -m; j <= m; j++){
- bool b = false;
- int curr = 0;
- REP(x, n){
- //DBG(x)
- REP(y, m){
- int x1 = x + i;
- int y1 = y + j;
- if(x1 < 0 || y1 < 0)continue;
- if(x1 >= n || y1 >= m)continue;
- if(water[x][y] && home[x1][y1]){
- b = true;
- break;
- }
- if(home[x1][y1]){
- for(int x_ = max((int)0, x - 1); x_ <= min(x + 1, n - 1); x_++){
- for(int y_ = max((int)0, y - 1); y_ <= min(y + 1, m - 1); y_++){
- //DBG(x_)
- //DBG(y_)
- if(water[x_][y_] && (x_ - x == 0 || y_ - y == 0)){
- //DBG("124")
- curr++;
- }
- //DBG("11111")
- }
- }
- }
- //DBG("!!!!")
- }
- // DBG("abcdt")
- //DBG(b)
- if(b)break;
- }
- if(!b){
- ans = max(ans, curr);
- }
- }
- }
- OUT(ans)
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement