답안 #22513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22513 2017-04-30T05:14:38 Z 예제는 나오는데 왜 틀리죠??(#895, baactree) Young Zebra (KRIII5_YZ) C++14
0 / 7
49 ms 18756 KB
// =====================================================================================
// 
//       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;
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:38:22: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1300]' [-Wformat=]
   scanf("%s", &mat[i]);
                      ^
YZ.cpp:36:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
YZ.cpp:38:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", &mat[i]);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 49 ms 18756 KB Output is partially correct
2 Incorrect 26 ms 18548 KB Output isn't correct
3 Halted 0 ms 0 KB -