結果

問題 No.2564 衝突予測
ユーザー viral8viral8
提出日時 2023-12-02 15:18:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 2,188 bytes
コンパイル時間 3,187 ms
コンパイル使用メモリ 77,880 KB
実行使用メモリ 62,136 KB
最終ジャッジ日時 2023-12-02 15:18:50
合計ジャッジ時間 9,615 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
54,116 KB
testcase_01 AC 53 ms
54,124 KB
testcase_02 AC 55 ms
54,116 KB
testcase_03 AC 534 ms
62,136 KB
testcase_04 AC 573 ms
61,756 KB
testcase_05 AC 536 ms
61,916 KB
testcase_06 AC 571 ms
62,072 KB
testcase_07 AC 544 ms
61,956 KB
testcase_08 AC 560 ms
61,812 KB
testcase_09 AC 530 ms
62,108 KB
testcase_10 AC 542 ms
62,116 KB
testcase_11 AC 562 ms
62,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
class Main{
	private static final BufferedReader br =
		new BufferedReader(new InputStreamReader(System.in));
	private static final PrintWriter out =
		new PrintWriter(System.out);
	public static void main(String[] args)throws IOException{

		int T = Integer.parseInt(br.readLine());
		while(T-->0){
			String[] str;
			str = br.readLine().split(" ");
			int x1 = Integer.parseInt(str[0]);
			int y1 = Integer.parseInt(str[1]);
			char d1 = str[2].charAt(0);
			str = br.readLine().split(" ");
			int x2 = Integer.parseInt(str[0]);
			int y2 = Integer.parseInt(str[1]);
			char d2 = str[2].charAt(0);
			if(x1==x2){
				if(y1<y2)
					out.println(d1=='U'&&d2=='D'?"Yes":"No");
				else
					out.println(d1=='D'&&d2=='U'?"Yes":"No");
			}
			else if(y1==y2){
				if(x1<x2)
					out.println(d1=='R'&&d2=='L'?"Yes":"No");
				else
					out.println(d1=='L'&&d2=='R'?"Yes":"No");
			}
			else{
				if((d1=='U'||d1=='D')&&(d2=='U'||d2=='D'))
					out.println("No");
				else if((d1=='L'||d1=='R')&&(d2=='L'||d2=='R'))
					out.println("No");
				else{
					int x3 = d1=='U'||d1=='D'?x1:x2;
					int y3 = d1=='L'||d1=='R'?y1:y2;
					if(x1<x3&&d1=='R'){
						if(y2<y3&&d2=='U')
							out.println(
								x3-x1==y3-y2?"Yes":"No");
						else if(y2>y3&&d2=='D')
							out.println(
								x3-x1==y2-y3?"Yes":"No");
						else
							out.println("No");
					}
					else if(x3<x1&&d1=='L'){
						if(y2<y3&&d2=='U')
							out.println(
								x1-x3==y3-y2?"Yes":"No");
						else if(y2>y3&&d2=='D')
							out.println(
								x1-x3==y2-y3?"Yes":"No");
						else
							out.println("No");
					}
					else if(y1<y3&&d1=='U'){
						if(x2<x3&&d2=='R')
							out.println(
								x3-x2==y3-y1?"Yes":"No");
						else if(x2>x3&&d2=='L')
							out.println(
								x2-x3==y3-y1?"Yes":"No");
						else
							out.println("No");
					}
					else if(y1>y3&&d1=='D'){
						if(x2<x3&&d2=='R')
							out.println(
								x3-x2==y1-y3?"Yes":"No");
						else if(x2>x3&&d2=='L')
							out.println(
								x2-x3==y1-y3?"Yes":"No");
						else
							out.println("No");
					}
					else
						out.println("No");
				}
			}
		}

		br.close();
		out.close();
	}
}
0