結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2015-01-15 20:43:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,944 bytes |
| コンパイル時間 | 2,377 ms |
| コンパイル使用メモリ | 78,812 KB |
| 実行使用メモリ | 67,084 KB |
| 最終ジャッジ日時 | 2024-06-22 11:46:50 |
| 合計ジャッジ時間 | 10,001 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 4 TLE * 1 -- * 21 |
ソースコード
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[] vx = {0,1,0,-1};
int[] vy={-1,0,1,0};
int[][] fromx = new int[row][column];
int[][] fromy = new int[row][column];
for(int i=0;i<row;i++){
for(int j=0;j<column;j++){
maze[i][j]=sc.nextInt();
}
}
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();
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])) && (fromx[ney][nex]!=nx||fromy[ney][nex]!=ny)&&moto1!=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);
fromx[ney][nex]=nx;
fromy[ney][nex]=ny;
if(nex == column-1 && ney == row-1){
System.out.println(nowho+1);
return;
}
}
}
}
System.out.println(-1);
}
}
kou6839