結果

問題 No.323 yuki国
ユーザー threepipes_sthreepipes_s
提出日時 2015-12-18 17:02:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,820 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 87,356 KB
実行使用メモリ 51,428 KB
最終ジャッジ日時 2023-10-14 14:00:13
合計ジャッジ時間 5,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,576 KB
testcase_01 AC 41 ms
49,656 KB
testcase_02 AC 42 ms
49,528 KB
testcase_03 AC 40 ms
49,536 KB
testcase_04 AC 42 ms
50,040 KB
testcase_05 AC 40 ms
49,732 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 42 ms
49,536 KB
testcase_09 AC 42 ms
49,720 KB
testcase_10 WA -
testcase_11 AC 41 ms
49,528 KB
testcase_12 AC 40 ms
49,716 KB
testcase_13 AC 42 ms
49,400 KB
testcase_14 AC 41 ms
47,832 KB
testcase_15 WA -
testcase_16 AC 42 ms
49,548 KB
testcase_17 AC 41 ms
49,536 KB
testcase_18 AC 41 ms
49,420 KB
testcase_19 AC 41 ms
49,524 KB
testcase_20 AC 43 ms
49,592 KB
testcase_21 AC 43 ms
49,528 KB
testcase_22 AC 43 ms
49,704 KB
testcase_23 AC 43 ms
49,612 KB
testcase_24 WA -
testcase_25 AC 49 ms
49,808 KB
testcase_26 AC 42 ms
49,528 KB
testcase_27 AC 43 ms
49,584 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 43 ms
47,676 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 41 ms
49,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Queue;
 
public class Main{
	public static void main(String[] args){
		try {(new Solve()).solve();}
		catch (NumberFormatException | IOException e) {e.printStackTrace();}
	}
}
 
class Solve{
	int h, w;
	void solve() throws NumberFormatException, IOException{
		final ContestScanner in = new ContestScanner();
		ContestWriter out = new ContestWriter();
		h = in.nextInt();
		w = in.nextInt();
		int a = in.nextInt();
		int sy = in.nextInt();
		int sx = in.nextInt();
		int b = in.nextInt();
		int gy = in.nextInt();
		int gx = in.nextInt();
		char[][] map = new char[h][];
		for(int i=0; i<h; i++){
			map[i] = in.nextToken().toCharArray();
		}
		BitSet used = new BitSet();
		Queue<Pos> qu = new ArrayDeque<>();
		final int[] dx = {1, 0, -1, 0};
		final int[] dy = {0, 1, 0, -1};
		qu.add(new Pos(sx, sy, a));
		int max = 0;
		out:while(!qu.isEmpty()){
			Pos p = qu.poll();
			if(p.x==gx && p.y==gy){
				max = Math.max(max, p.s);
			}
			for(int i=0; i<4; i++){
				final int ny = dy[i]+p.y;
				final int nx = dx[i]+p.x;
				if(out(ny, nx)) continue;
				if(map[ny][nx]=='.'&&p.s==1) continue;
				int ns = p.s+(map[ny][nx]=='.'?-1:1);
				if(used.get(ny<<6|nx) || ns==0) continue;
				used.set(ny<<6|nx);
				if(map[p.y][p.x]=='*'&&map[ny][nx]=='*'){
					max = ns+1200-dist(gx, gy, ny, nx);
					break out;
				}
				qu.add(new Pos(nx, ny, ns));
			}
		}

		if(b<=max && max%2==b%2){
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}
	
	int dist(int x1, int y1, int x2, int y2){
		return Math.abs(x1-x2) + Math.abs(y1-y2);
	}
	
	boolean out(int y, int x){
		return y<0||y>=h||x<0||x>=w;
	}
}

class Pos implements Comparable<Pos>{
	int id, x, y, s;
	Pos(int x, int y, int s){
		this.x = x;
		this.y = y;
		this.s = s;
		id = y<<6|x;
	}
	@Override
	public int compareTo(Pos o) {
		return o.s-s;
	}
	@Override
	public String toString() {
		return "("+x+","+y+","+s+")";
	}
}

class MultiSet<T> extends HashMap<T, Integer>{
	@Override
	public Integer get(Object key){return containsKey(key)?super.get(key):0;}
	public void add(T key,int v){put(key,get(key)+v);}
	public void add(T key){put(key,get(key)+1);}
}
 
class ContestWriter{
	private PrintWriter out;
	public ContestWriter(String filename) throws IOException
	{out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));}
	public ContestWriter() throws IOException{out = new PrintWriter(System.out);}
	public void println(String str){out.println(str);}
	public void println(Object str){out.println(str);}
	public void print(String str){out.print(str);}
	public void close(){out.close();}
}
 
class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;
	public ContestScanner()throws FileNotFoundException 
	{reader=new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename)throws FileNotFoundException
	{reader=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken()throws IOException{if(line==null||line.length<=idx){
	line=reader.readLine().trim().split(" ");idx=0;}return line[idx++];}
	public String readLine()throws IOException{return reader.readLine();}
	public long nextLong()throws IOException,NumberFormatException{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
}
0