제출 #22505

#제출 시각아이디문제언어결과실행 시간메모리
22505크리콘 B번 문제는 그리디로 풀려요 (#40)Young Zebra (KRIII5_YZ)C++98
7 / 7
63 ms15952 KiB
#include<stdio.h>
#include<memory.h>
#define mod(a,b) (((a)%(b)+(b))%b)

int N, M;
char ba[555][555]; int dap[555][555];
int chk1[555][555], xy[555][555][2];

int cnt, err, xx[4]={0,0,1,-1}, yy[4]={1,-1,0,0};
void dfs1(int x, int y, char gr, int ty, int val){
	int x2=mod(x,N), y2=mod(y,M);
	if(ba[x2][y2] != gr) return;
	if(chk1[x2][y2] != ty){
		if(xy[x2][y2][0] != x || xy[x2][y2][1] != y) err=1;
		return;
	}
	xy[x2][y2][0]=x, xy[x2][y2][1]=y;
	chk1[x2][y2]++; cnt++;
	if(val) dap[x2][y2]=val;
	for(int i=0; i<4; i++)dfs1(x+xx[i], y+yy[i], gr, ty, val);
}

int main(){
	scanf("%d%d\n", &N, &M);
	for(int i=0; i<N; i++)gets(ba[i]);
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			if(chk1[i][j])continue;
			cnt=0, err=0, dfs1(i, j, ba[i][j], 0, 0);
			dfs1(i, j, ba[i][j], 1, err?-1:cnt);
		}
	}

	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++)printf("%d ", dap[i][j]);
		puts("");
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

YZ.cpp: In function 'int main()':
YZ.cpp:25:24: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
  for(int i=0; i<N; i++)gets(ba[i]);
                        ^
In file included from YZ.cpp:1:0:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
YZ.cpp:25:24: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
  for(int i=0; i<N; i++)gets(ba[i]);
                        ^
In file included from YZ.cpp:1:0:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
YZ.cpp:25:34: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
  for(int i=0; i<N; i++)gets(ba[i]);
                                  ^
In file included from YZ.cpp:1:0:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
YZ.cpp:24:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d\n", &N, &M);
                         ^
YZ.cpp:25:35: warning: ignoring return value of 'char* gets(char*)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<N; i++)gets(ba[i]);
                                   ^
/tmp/ccCLQQqf.o: In function `main':
YZ.cpp:(.text.startup+0x4e): warning: the `gets' function is dangerous and should not be used.
#Verdict Execution timeMemoryGrader output
Fetching results...