結果
| 問題 |
No.323 yuki国
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-27 19:35:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 705 ms / 5,000 ms |
| コード長 | 3,280 bytes |
| コンパイル時間 | 5,491 ms |
| コンパイル使用メモリ | 79,912 KB |
| 実行使用メモリ | 57,076 KB |
| 最終ジャッジ日時 | 2024-06-28 12:32:57 |
| 合計ジャッジ時間 | 12,331 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 32 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Iterator;
public class Main_yukicoder323_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Printer pr = new Printer(System.out);
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[][] akichi = new char[h][];
for (int i = 0; i < h; i++) {
akichi[i] = sc.next().toCharArray();
}
if (Math.abs(a - b) % 2 != Math.abs(si - gi + sj - gj) % 2) {
pr.println("No");
sc.close();
pr.close();
return;
}
int[] di = {-1, 0, 1, 0};
int[] dj = {0, 1, 0, -1};
int max = Math.max(a, b) + h * w;
boolean[][][] used = new boolean[h][w][max + 1];
Deque<Integer> qi = new ArrayDeque<Integer>();
Deque<Integer> qj = new ArrayDeque<Integer>();
Deque<Integer> qs = new ArrayDeque<Integer>();
qi.add(si);
qj.add(sj);
qs.add(a);
used[si][sj][a] = true;
while (!qi.isEmpty()) {
int i = qi.remove();
int j = qj.remove();
int size = qs.remove();
for (int k = 0; k < di.length; k++) {
int ni = i + di[k];
int nj = j + dj[k];
if (ni < 0 || ni >= h || nj < 0 || nj >= w) {
continue;
}
int nyuki;
if (akichi[ni][nj] == '*') {
nyuki = size + 1;
} else {
nyuki = size - 1;
}
if (nyuki == 0) {
continue;
}
if (nyuki > max || used[ni][nj][nyuki]) {
continue;
}
used[ni][nj][nyuki] = true;
qi.add(ni);
qj.add(nj);
qs.add(nyuki);
}
}
if (used[gi][gj][b]) {
pr.println("Yes");
} else {
pr.println("No");
}
pr.close();
sc.close();
}
@SuppressWarnings("unused")
private static class Scanner {
BufferedReader br;
Iterator<String> it;
Scanner (InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
String next() throws RuntimeException {
try {
if (it == null || !it.hasNext()) {
it = Arrays.asList(br.readLine().split(" ")).iterator();
}
return it.next();
} catch (IOException e) {
throw new IllegalStateException();
}
}
int nextInt() throws RuntimeException {
return Integer.parseInt(next());
}
long nextLong() throws RuntimeException {
return Long.parseLong(next());
}
float nextFloat() throws RuntimeException {
return Float.parseFloat(next());
}
double nextDouble() throws RuntimeException {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
// throw new IllegalStateException();
}
}
}
private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}