結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2015-01-15 20:25:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,028 bytes |
| コンパイル時間 | 2,760 ms |
| コンパイル使用メモリ | 79,948 KB |
| 実行使用メモリ | 1,313,320 KB |
| 最終ジャッジ日時 | 2024-06-22 11:45:31 |
| 合計ジャッジ時間 | 14,583 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | MLE * 1 -- * 25 |
ソースコード
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int column = sc.nextInt();
int row = sc.nextInt();
int[][] maze = new int[row][column];
int[][] ho = new int[row][column];
int[] vx = {0,1,0,-1};
int[] vy={-1,0,1,0};
for(int i=0;i<row;i++) Arrays.fill(ho[i],-1);
for(int i=0;i<row;i++){
for(int j=0;j<column;j++){
maze[i][j]=sc.nextInt();
}
}
ho[0][0]=0;
ho[0][1]=1;
ho[1][0]=1;
Queue<Integer> quex = new LinkedList<Integer>();
Queue<Integer> quey = new LinkedList<Integer>();
Queue<Integer> moto = new LinkedList<Integer>();
Queue<Integer> hoo = new LinkedList<Integer>();
quex.offer(1);
quey.offer(0);
quex.offer(0);
quey.offer(1);
hoo.offer(1);
hoo.offer(1);
moto.offer(maze[0][0]);
moto.offer(maze[0][0]);
while(!quex.isEmpty()){
int nx = quex.poll();
int ny = quey.poll();
int nowho = hoo.poll();
if(nx == column && ny == row){
System.out.println(ho[nx][ny]);
return;
}
int moto1 = moto.poll();
for(int i=0;i<4;i++){
int nex = nx+vx[i];
int ney = ny+vy[i];
if(nex<0 || nex > column-1 || ney<0 || ney > row-1) continue;
if( ((moto1 > maze[ny][nx] && maze[ney][nex]>maze[ny][nx]) || (moto1 < maze[ny][nx] && maze[ney][nex]<maze[ny][nx])) &&moto1 != maze[ney][nex] && maze[ny][nx]!=maze[ney][nex]){
quex.offer(nex);
quey.offer(ney);
moto.offer(maze[ny][nx]);
hoo.offer(nowho+1);
ho[ney][nex]=ho[ny][nx]+1;
if(nex == column-1 && ney == row-1){
System.out.println(nowho+1);
return;
}
}
}
}
System.out.println(-1);
}
}
kou6839