#include<iostream>
#include<fstream>
#define fin cin
#define fout cout
#include<vector>
using namespace std;
//ifstream fin("date.in");
//ofstream fout("date.out");
int i,j,a,ss,nr,ds,sj,dj,s,d,n,m,f[6];
int ddi[4]={0,0,1,-1};
int ddj[4]={-1,1,0,0};
char v[15][15];
void fil(int x,int y)
{
char val=v[x][y];
if(y==s)
{
if(x<ss) ss=x;
if(x>sj) sj=x;
}
if(y<s) s=y,ss=x,sj=x;
if(y==d)
{
if(x<ds) ds=x;
if(x>dj) dj=x;
}
if(y>d) d=y,ds=x,dj=x;
v[x][y]='.';
int ix,iy;
for(int dd=0;dd<=3;dd++)
{
ix=x+ddi[dd];
iy=y+ddj[dd];
if(ix>=0&&iy>=0&&ix<n&&iy<m&&v[ix][iy]==val) fil(ix,iy);
}
}
int main(){
fin>>n>>m;
for(i=0;i<n;i++) fin>>v[i];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(v[i][j]!='.')
{
d=-1;s=10001;nr++;
fil(i,j);
if(ss==sj&&ds==dj)
{
if(ds>ss) f[4]++;
if(ds<ss) f[3]++;
if(ds==ss)
{
if(d-s==2) f[5]++;
else f[2]++;
}
continue;
}
if(ss==sj||ds==dj){f[5]++;continue;}
if(s==d){f[2]++;continue;}
if(ds==ss) f[1]++;
if(ds>ss) f[3]++;
if(ds<ss) f[4]++;
}
}
for(nr=1;nr<=5;nr++) fout<<f[nr]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |