# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22513 | 예제는 나오는데 왜 틀리죠?? (#40) | Young Zebra (KRIII5_YZ) | C++14 | 49 ms | 18756 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// =====================================================================================
//
// Filename: yz.cpp
// Created: 2017년 04월 30일 13시 55분 22초
// Compiler: g++ -O2 -std=c++14
// Author: baactree , [email protected]
// 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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |