# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22527 | 예제는 나오는데 왜 틀리죠?? (#40) | Young Zebra (KRIII5_YZ) | C++14 | 49 ms | 18760 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.
// =====================================================================================
//
// Filename: yz.cpp
// Created: 2017년 04월 30일 13시 55분 22초
// Compiler: g++ -O2 -std=c++14
// Author: baactree , bsj0206@naver.com
// Company: Chonnam National University
//
// =====================================================================================
#include <bits/stdc++.h>
using namespace std;
int n, m;
char mat[1300][1300];
int check[1205][1205];
int _count[1205*1205];
int trip[3][3];
int dx[4]={-1, 1, 0, 0};
int dy[4]={0, 0, -1, 1};
bool safe(int x, int y){
return x>=0&&x<3*n&&y>=0&&y<3*m;
}
int dfs(int x, int y, int idx){
trip[x/n][y/m]=true;
check[x][y]=idx;
int ret=1;
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(safe(nx, ny)&&!check[nx][ny]&&mat[nx][ny]==mat[x][y])
ret+=dfs(nx, ny, idx);
}
return ret;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=0;i<n;i++)
scanf("%s", &mat[i]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
mat[i+n][j]=mat[i+n*2][j]=mat[i][j+m]=mat[i+n][j+m]=mat[i+n*2][j+m]=
mat[i][j+m*2]=mat[i+n][j+m*2]=mat[i+n*2][j+m*2]=mat[i][j];
}
int idx=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
if(!check[i+n][j+m]){
memset(trip, 0, sizeof(trip));
int temp=dfs(i+n, j+m, idx);
// if(trip[1][0]&&trip[1][1]&&trip[1][2])
// temp=-1;
// if(trip[0][1]&&trip[1][1]&&trip[2][1])
// temp=-1;
_count[idx]=temp;
idx++;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
printf("%d ", _count[check[i+n][j+m]]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |