# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472745 | MamdouhN | Tetris (COCI17_tetris) | C++14 | 1 ms | 204 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 int long long
#define endl "\n"
int n,m;
char ar[11][11];
vector<pair<int,int>>points;
map<int,int>repsx,repsy;
int shapes[6];
void solve(int x,int y,char color)
{
if(ar[x][y]!=color)return;
points.push_back({x,y});
ar[x][y] = '.';
if(x<n-1)solve(x+1,y,color);
if(y>0)solve(x,y-1,color);
if(y<m-1)solve(x,y+1,color);
}
void determine_shape()
{
repsx.clear();
repsy.clear();
int ret = -1;
for(auto v:points)
{
repsx[v.first]++;
repsy[v.second]++;
//cout<<v.first<<" "<<v.second<<" "<<repsx[v.first]<<" "<<repsy[v.second]<<endl;
if(repsx[v.first]==4||repsy[v.second]==4)ret =1;
if(repsx[v.first]==3||repsy[v.second]==3)ret =4;
}
//cout<<ret<<endl;
if(ret!=-1)
{
shapes[ret]++;
return;
}
bool square = 1;
int x=0,y=0;
for(auto v:repsx)
{
if(v.second!=2)square=0;
else x+=1;
}
for(auto v:repsy)
{
if(v.second!=2)square=0;
else y+=1;
}
if(square)ret = 0;
if(ret!=-1)
{
shapes[ret]++;
return;
}
if(y==2)
{
int mini = 0;
int maxi = 0;
for(int i=0;i<points.size();i++)
{
if(points[i].first<points[mini].first)mini=i;
if(points[i].first>points[maxi].first)maxi=i;
}
mini=points[mini].second;
maxi=points[maxi].second;
if(maxi<mini)ret = 3;
else ret = 2;
//cout<<"rety is "<<ret<<endl;
shapes[ret]++;
return;
}
if(x==2)
{
int mini = 0;
int maxi = 0;
for(int i=0;i<points.size();i++)
{
if(points[i].second<points[mini].second)mini=i;
if(points[i].second>points[maxi].second)maxi=i;
}
mini=points[mini].first;
maxi=points[maxi].first;
if(maxi<mini)ret = 2;
else ret = 3;
//cout<<"retx is "<<ret<<endl;
shapes[ret]++;
return;
}
}
void print_grid()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<ar[i][j];
}
cout<<endl;
}
}
main()
{
cin>>n>>m;
for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>ar[i][j];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
//cout<<"hddi "<<i<<" "<<j<<endl;
if(ar[i][j]=='.')continue;
points.clear();
solve(i,j,ar[i][j]);
//print_grid();
determine_shape();
//cout<<"Hola soi dora"<<endl;
}
}
for(int i=0;i<5;i++)cout<<shapes[i]<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |