結果

問題 No.13 囲みたい!
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-19 01:30:25
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,330 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 22,400 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:20:32
合計ジャッジ時間 1,398 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 15 ms
5,376 KB
testcase_09 AC 15 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 12 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:52:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |         scanf("%d %d", &W, &H);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:56:25: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |                         scanf("%d", &board[i][j]);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <string.h>
#include <stdio.h>

#define WHMAX	(100)
#define GUARD	(9999)

int spos;
int stack[WHMAX*WHMAX+100];

int board[WHMAX+5][WHMAX+5];
int board2[WHMAX+5][WHMAX+5];

int saiki(int nx, int ny, int num, int cnt){
	int i, ret = 0;
	int px[] = {-1, 0, 1, 0};
	int py[] = { 0,-1, 0, 1};
	
	board2[ny][nx] = cnt;
	board[ny][nx] = 0;
	
	for(i=0;i<4;i++){
		int next = board2[ny+py[i]][nx+px[i]];
		if(next == (board2[ny][nx]-1)){continue;}
		if(next != 0){
			ret = 1;
			break;
		}
		if(board[ny+py[i]][nx+px[i]] == GUARD){continue;}
		if(board[ny+py[i]][nx+px[i]] == num){
//			printf("%d %d %d %d %d %d \n", nx, ny, nx+px[i], ny+py[i], num, next, cnt);
			ret = saiki(nx+px[i], ny+py[i], num, cnt+1);
		}
		
		if(ret == 1){
			break;
		}
	}
	
	return ret;
}

int main(void){
	int i,j,W,H;
	int ret=0;
	
	for(i=0;i<WHMAX+5;i++){
		for(j=0;j<WHMAX+5;j++){
			board[i][j] = GUARD;
		}
	}
	
	scanf("%d %d", &W, &H);
	
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			scanf("%d", &board[i][j]);
		}
	}
	
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			int tmp;
			if(board[i][j] == 0){continue;}
			
			memset(board2, 0, sizeof(board2));
			tmp = board[i][j];
			ret = saiki(j,i,tmp, 2);
			
			if(ret == 1){
				i=H+5;
				j=W+5;
			}
		}
	}
	
	if(ret == 1){
		printf("possible\n");
	}else{
		printf("impossible\n");
	}
	return 0;
}
0