# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151911 | phillip | Tetris (COCI17_tetris) | C++14 | 4 ms | 376 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;
char g[20][20];
bool vis[20][20];
int f[5],n,m;
bool isc(int x,int y)
{
char c=g[x][y];
for(int i=x;i<x+4;i++)
{
if(g[i][y]!=c)break;
if(i==x+3)
{
f[1]++;
for(int i=x;i<x+4;i++)vis[i][y]=1;
return true;
}
}
for(int i=y;i<y+4;i++)
{
if(g[x][i]!=c)break;
if(i==y+3)
{
f[1]++;
for(int i=y;i<y+4;i++)vis[x][i]=1;
return true;
}
}
return false;
}
bool issq(int x,int y)
{
char c=g[x][y];
if(g[x+1][y]==c&&g[x][y+1]==c&&g[x+1][y+1]==c)
{
f[0]++;
vis[x][y]=1;vis[x+1][y]=1;vis[x][y+1]=1;vis[x+1][y+1]=1;
return true;
}
return false;
}
bool issh(int x,int y)
{
char c=g[x][y];
if(g[x+1][y-1]==c&&g[x][y+1]==c)
{
f[2]++;
// cout<<"issh";
return true;
}
return false;
}
queue<pair<int,int> >q;
int main()
{
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++)g[i][j]='.';
}
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>g[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(g[i][j]=='.')continue;
if(vis[i][j])continue;
/*for(int i=0;i<5;i++)
{
cout<<f[i]<<" ";
}
cout<<"\n";*/
//cout<<i<<" "<<j<<"\n";
if(isc(i,j))continue;
if(issq(i,j))continue;
char c=g[i][j];
q.push({i,j});
int x,y;
bool o=0;
int smd=0,smc=0;
while(!q.empty())
{
x=q.front().first;y=q.front().second;
q.pop();
if(vis[x][y])continue;
vis[x][y]=1;
int num=0;
if(g[x+1][y]==c)q.push({x+1,y}),num++;
if(g[x+1][y]==c&&vis[x+1][y]==0)smd++;
if(g[x-1][y]==c)q.push({x-1,y}),num++;
if(g[x-1][y]==c&&vis[x-1][y]==0)smd--;
if(g[x][y+1]==c)q.push({x,y+1}),num++;
if(g[x][y+1]==c&&vis[x][y+1]==0)smc++;
if(g[x][y-1]==c)q.push({x,y-1}),num++;
if(g[x][y-1]==c&&vis[x][y-1]==0)smc--;
if(num==3)
{
o=1;
}
}
if(o)
{
f[4]++;
continue;
}
if(smd==2&&smc==1)
{
// cout<<"clean";
f[2]++;
continue;
}
if(issh(i,j))continue;
f[3]++;
}
}
for(int i=0;i<5;i++)
{
cout<<f[i]<<"\n";
}
}
/*
3 3
aa.
.aa
...*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |