Submission #884315

# Submission time Handle Problem Language Result Execution time Memory
884315 2023-12-07T06:41:20 Z vjudge1 Tetris (COCI17_tetris) C++17
80 / 80
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 2e5+1;
const int MOD = 1e9+7;

void solve() {
  int n,m;
  cin >> n >> m;
  char a[n+1][m+1];
  F(i,n) {
    string s;
    cin >> s;
    F(j,m) a[i][j] = s[j-1];
  }
  vi ans(6,0);
  F(i,n) {
    F(j,m) {
      if (a[i][j] == '.') continue;
      if (i<n-1 && j<m) {
        if (a[i][j] == a[i+1][j] && a[i+1][j]==a[i+1][j+1] && a[i+1][j+1]==a[i+2][j+1]) {
          ans[3]++;
          continue;
        }
      }
      if (i<n && j>1 && j<m) {
        if (a[i][j] == a[i][j+1] && a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j-1]) {
          ans[3]++;
          continue;
        }
      }
      if (i<n-1 && j>1) {
        if (a[i][j] == a[i+1][j] && a[i+1][j]==a[i+1][j-1] && a[i+1][j-1]==a[i+2][j-1]) {
          ans[4]++;
          continue;
        }
      }
      if (i<n && j<m-1) {
        if (a[i][j] == a[i][j+1] && a[i][j+1] == a[i+1][j+1] && a[i+1][j+1] == a[i+1][j+2]) {
          ans[4]++;
          continue;
        }
      }
    }
  }
  vi dx = {0,1,0,-1};
  vi dy = {1,0,-1,0};
  int adj[n+5][m+5];
  memset(adj,0,sizeof adj);
  F(i,n) {
    F(j,m) {
      for (int k=0;k<4;k++) {
        int gx = i+dx[k];
        int gy = j+dy[k];
        if (gx >= 1 && gx <= n && gy >= 1 && gy <= m && a[gx][gy]>='a' && a[gx][gy]<='z' && a[gx][gy] == a[i][j]) {
          adj[i][j]++;
        }
      }
    }
  }
  F(i,n) {
    F(j,m) {
      if (adj[i][j] == 3) {
        ans[5]++;
      }
    }
  }
  F(i,n) {
    F(j,m) {
      if (j<m-2 && adj[i][j] == 1 && adj[i][j+1] == 2 && adj[i][j+2] == 2 && adj[i][j+3] == 1 && a[i][j] == a[i][j+1] && a[i][j+1] ==a[i][j+2] && a[i][j+3] == a[i][j+2]) {
        ans[2]++;
      }

    }
  }
  F(i,n) {
    F(j,m) {
      if (i<n-2 && adj[i][j] == 1 && adj[i+1][j] == 2 && adj[i+2][j] == 2 && adj[i+3][j] == 1 && a[i][j] == a[i+1][j] && a[i+1][j] == a[i+2][j] && a[i+2][j] == a[i+3][j]) {
        ans[2]++;
      }
    }
  }

  F(i,n){
    F(j,m) {
      if (a[i][j] == '.') continue;
      if (i<n && j<m && a[i][j] == a[i+1][j] && a[i+1][j] == a[i][j+1] && a[i][j+1] == a[i+1][j+1]) {
        ans[1]++;
      }
    }
  }
  F(i,5) cout << ans[i] << "\n";
}
    
                  
                             
signed main() { 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifdef Local
  freopen("in","r",stdin);
  freopen("out","w",stdout); 
  #endif
  int t = 1;
  //cin >> t;
	F(i,t) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct