結果
| 問題 |
No.323 yuki国
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-12-15 20:33:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 318 ms / 5,000 ms |
| コード長 | 1,441 bytes |
| コンパイル時間 | 2,283 ms |
| コンパイル使用メモリ | 78,616 KB |
| 実行使用メモリ | 59,520 KB |
| 最終ジャッジ日時 | 2024-06-28 12:14:25 |
| 合計ジャッジ時間 | 11,376 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 32 |
ソースコード
package yukiguni;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int w = sc.nextInt();
int a = sc.nextInt();
int si = sc.nextInt();
int sj = sc.nextInt();
int b = sc.nextInt();
int gi = sc.nextInt();
int gj = sc.nextInt();
char[][] m = new char[h][];
for(int i=0;i<h;i++) {
m[i] = sc.next().toCharArray();
}
sc.close();
System.out.println(solve(h,w,a,b,si,sj,gi,gj,m) ? "Yes" : "No");
}
public static final int[] DI = {0,-1,0,1};
public static final int[] DJ = {1,0,-1,0};
public static boolean solve(int h,int w,int a,int b,int si,int sj,int gi,int gj,char[][] m) {
int max = Math.max(a+h+w-1,b+2*(h+w));
boolean[][][] used = new boolean[h][w][max+1];
Queue<Integer> q = new ArrayDeque<>();
q.offer(a << 16 | si << 8 | sj);
used[si][sj][a] = true;
while(!q.isEmpty()) {
int p = q.poll();
int cs = p >>> 16;
int ci = p >>> 8 & 0xff;
int cj = p & 0xff;
for(int i=0;i<4;i++) {
int ni = ci + DI[i];
int nj = cj + DJ[i];
if (ni < 0 || ni >= h || nj < 0 || nj >= w) {
continue;
}
int ns = cs + (m[ni][nj] == '*' ? 1 : -1);
if (ns > max || ns <= 0 || used[ni][nj][ns]) {
continue;
}
used[ni][nj][ns] = true;
q.offer(ns << 16 | ni << 8 | nj);
}
}
return used[gi][gj][b];
}
}
ぴろず