結果
| 問題 |
No.323 yuki国
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2015-12-16 00:53:27 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 554 ms / 5,000 ms |
| コード長 | 1,613 bytes |
| コンパイル時間 | 2,221 ms |
| コンパイル使用メモリ | 78,632 KB |
| 実行使用メモリ | 97,864 KB |
| 最終ジャッジ日時 | 2024-06-28 12:19:40 |
| 合計ジャッジ時間 | 12,986 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 32 |
ソースコード
import java.util.*;
public class Main {
static class snow{
int x,y,unko;
public snow(int x,int y,int unko) {
// TODO Auto-generated constructor stub
this.x = x;
this.y = y;
this.unko = unko;
}
}
static long gcd(long a,long b){
return b == 0 ? a : gcd(b, a%b);
}
static long lcm(long a, long b){
return a*b/gcd(a, b);
}
static int[] dx = {1,0,-1,0};
static int[] dy = {0,1,0,-1};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int a = sc.nextInt();
int sx = sc.nextInt();
int sy = sc.nextInt();
int b = sc.nextInt();
int gx = sc.nextInt();
int gy = sc.nextInt();
boolean[][] map = new boolean[x][y];
for(int i=0;i<x;i++){
String tmp = sc.next();
for(int j=0;j<y;j++){
if(tmp.charAt(j)=='*') map[i][j]=true;
}
}
boolean[][][] checked = new boolean[x][y][10000];
Queue<snow> queue = new LinkedList<>();
queue.add(new snow(sx, sy, a));
int count = 0;
while(!queue.isEmpty()){
snow now = queue.poll();
count++;
if(count>3000000) break;
if(now.x == gx && now.y == gy && now.unko == b){
System.out.println("Yes");
return;
}
for(int i=0;i<4;i++){
int nextx = now.x+dx[i];
int nexty = now.y+dy[i];
if(nextx>=0 &&nextx<x && nexty>=0 && nexty<y){
int nextunk = now.unko+ (map[nextx][nexty]?1:-1);
if(nextunk<=0 || nextunk > 5000|| checked[nextx][nexty][nextunk]) continue;
queue.add(new snow(nextx, nexty, nextunk));
checked[nextx][nexty][nextunk]=true;
}
}
}
System.out.println("No");
}
}
kou6839