結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  kou6839 | 
| 提出日時 | 2014-11-11 17:18:52 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 313 ms / 5,000 ms | 
| コード長 | 1,238 bytes | 
| コンパイル時間 | 2,096 ms | 
| コンパイル使用メモリ | 76,968 KB | 
| 実行使用メモリ | 59,068 KB | 
| 最終ジャッジ日時 | 2024-10-13 10:38:43 | 
| 合計ジャッジ時間 | 5,912 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
import java.util.*;
 
public class Main {
	static int[][] map;
	static boolean[][] check;
	static int[] vr={1,0,-1,0};
	static int[] vc={0,1,0,-1};
	static int column;
	static int row;
	static boolean dfs(int nowr,int nowc,int fromr,int fromc,boolean[][] tesuto,int num){
		check[nowr][nowc]=true;
		tesuto[nowr][nowc]=true;
		for(int i=0;i<4;i++){
			int nr=nowr+vr[i];
			int nc=nowc+vc[i];
			if(0<=nr&&nr<row&&0<=nc&&nc<column&&map[nr][nc]==num&&!(nr==fromr&&nc==fromc)){
				if(tesuto[nr][nc]) return true;
				if(dfs(nr,nc,nowr,nowc,tesuto,num)) return true;;
			}
		}
		return false;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		column=sc.nextInt();
		row = sc.nextInt();
		map =new int[row][column];
		 check = new boolean[row][column];
		for(int i=0;i<row;i++){
			for(int j=0;j<column;j++){
				map[i][j]=sc.nextInt();
			}
		}
		for(int i=0;i<row;i++){
			for(int j=0;j<column;j++){
				if(!check[i][j]){
					int num=map[i][j];
					boolean[][] tesuto=new boolean[row][column];
					if(dfs(i,j,-1,-1,tesuto,num)) {
						
					System.out.println("possible");
					return;
					}
				}
			}
		}
		System.out.println("impossible");
	}
}	
            
            
            
        