# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884314 | vjudge1 | Tetris (COCI17_tetris) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
bool ctd[n+1][m+1];
memset(ctd,0,sizeof ctd);
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 (ctd[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]) {
ctd[i][j] = ctd[i+1][j] = ctd[i+1][j+1] = ctd[i+2][j+1] = 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]) {
ctd[i][j] = ctd[i][j+1] = ctd[i+1][j] = ctd[i+1][j-1] = 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]) {
ctd[i][j] = ctd[i+1][j] = ctd[i+1][j-1] = ctd[i+2][j-1] = 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]) {
ctd[i][j] = ctd[i][j+1] = ctd[i+1][j+1] = ctd[i+1][j+2] = 1;
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 (ctd[i][j]) continue;
if (adj[i][j] == 3) {
ans[5]++;
ctd[i][j] = ctd[i][j+1] = ctd[i][j-1] = ctd[i-1][j] = 1;
}
}
}
F(i,n) {
F(j,m) {
if (ctd[i][j]) continue;
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]++;
ctd[i][j] = ctd[i][j+1] = ctd[i][j+2] = ctd[i][j+3] = 1;
}
}
}
F(i,n) {
F(j,m) {
if (ctd[i][j]) continue;
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]++;
ctd[i][j] = ctd[i+1][j] = ctd[i+2][j] = ctd[i+3][j] = 1;
}
}
}
F(i,n){
F(j,m) {
if (a[i][j] == '.') continue;
if (ctd[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 |
---|---|---|---|---|
Fetching results... |