結果
| 問題 |
No.2564 衝突予測
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2025-02-18 16:59:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 661 ms / 2,000 ms |
| コード長 | 5,708 bytes |
| コンパイル時間 | 5,263 ms |
| コンパイル使用メモリ | 108,096 KB |
| 実行使用メモリ | 40,960 KB |
| 最終ジャッジ日時 | 2025-02-18 16:59:34 |
| 合計ジャッジ時間 | 12,193 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
// https://yukicoder.me/problems/no/2564
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("2");
WillReturn.Add("1 1 U");
WillReturn.Add("1 5 D");
WillReturn.Add("3 2 U");
WillReturn.Add("5 4 L");
}
else if (InputPattern == "Input2") {
WillReturn.Add("1");
WillReturn.Add("1 2 L");
WillReturn.Add("3 4 D");
}
else if (InputPattern == "Input3") {
WillReturn.Add("3");
WillReturn.Add("998244353 0 U");
WillReturn.Add("0 998244353 R");
WillReturn.Add("998244353 998244353 U");
WillReturn.Add("0 0 D");
WillReturn.Add("0 0 R");
WillReturn.Add("998244353 0 L");
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
for (int I = 1; I <= InputList.Count - 1; I += 2) {
string[] SpilitArr1 = InputList[I].Split(' ');
string[] SpilitArr2 = InputList[I + 1].Split(' ');
decimal X1 = decimal.Parse(SpilitArr1[0]);
decimal Y1 = decimal.Parse(SpilitArr1[1]);
string D1 = SpilitArr1[2];
decimal X2 = decimal.Parse(SpilitArr2[0]);
decimal Y2 = decimal.Parse(SpilitArr2[1]);
string D2 = SpilitArr2[2];
string Result = Solve(X1, Y1, D1, X2, Y2, D2);
Console.WriteLine(Result);
}
}
static string Solve(decimal pX1, decimal pY1, string pD1, decimal pX2, decimal pY2, string pD2)
{
// 場合1 X座標が等しい場合
if (pX1 == pX2) {
if (pY1 < pY2) {
if (pD2 == "D" && pD1 == "U") {
return "Yes";
}
}
if (pY1 > pY2) {
if (pD2 == "U" && pD1 == "D") {
return "Yes";
}
}
return "No";
}
// 場合2 Y座標が等しい場合
if (pY1 == pY2) {
if (pX1 < pX2) {
if (pD2 == "L" && pD1 == "R") {
return "Yes";
}
}
if (pX1 > pX2) {
if (pD2 == "R" && pD1 == "L") {
return "Yes";
}
}
return "No";
}
// 場合3 三分探索
decimal XDiff = Math.Abs(pX1 - pX2);
decimal NewPosX1, NewPosY1;
DerivePos(pX1, pY1, pD1, XDiff, out NewPosX1, out NewPosY1);
decimal NewPosX2, NewPosY2;
DerivePos(pX2, pY2, pD2, XDiff, out NewPosX2, out NewPosY2);
decimal CurrNorm = DeriveNorm(NewPosX1, NewPosY1, NewPosX2, NewPosY2);
if (CurrNorm == 0) {
return "Yes";
}
//decimal FirstNorm = DeriveNorm(pX1, pY1, pX2, pY2);
//decimal NewPosX1, NewPosY1;
//DerivePos(pX1, pY1, pD1, 1, out NewPosX1, out NewPosY1);
//decimal NewPosX2, NewPosY2;
//DerivePos(pX2, pY2, pD2, 1, out NewPosX2, out NewPosY2);
//decimal SecondNorm = DeriveNorm(NewPosX1, NewPosY1, NewPosX2, NewPosY2);
//if (SecondNorm == 0) {
// return "Yes";
//}
//// Tを引数として、距離のNormを返す
//Func<long, decimal> CalcFunc = pT =>
//{
// DerivePos(pX1, pY1, pD1, 1, out NewPosX1, out NewPosY1);
// DerivePos(pX2, pY2, pD2, 1, out NewPosX2, out NewPosY2);
// return DeriveNorm(NewPosX1, NewPosY1, NewPosX2, NewPosY2);
//};
//if (FirstNorm > SecondNorm) {
// long L = 1;
// long R = (long)Math.Max(Math.Abs(pX1 - pX2), Math.Abs(pY1 - pY2));
// var PairHashSet = new HashSet<string>();
// while (L + 1 < R) {
// long C1 = (L * 2 + R) / 3;
// long C2 = (L + R * 2) / 3;
// decimal C1Val = CalcFunc(C1);
// decimal C2Val = CalcFunc(C2);
// if (C1Val < C2Val) {
// R = C2;
// }
// else {
// L = C1;
// }
// string Hash = string.Format("{0},{1}", L, R);
// if (PairHashSet.Add(Hash) == false) {
// break;
// }
// }
// var MinKouhoList = new List<decimal>();
// for (long I = L; I <= R; I++) {
// MinKouhoList.Add(CalcFunc(I));
// }
// if (MinKouhoList.Min() == 0) {
// return "Yes";
// }
//}
return "No";
}
// T秒後の座標を返す
static void DerivePos(decimal pInitX, decimal pInitY, string pD, decimal pT, out decimal pNewX, out decimal pNewY)
{
decimal VectX = 0;
decimal VectY = 0;
if (pD == "R") VectX = 1;
if (pD == "L") VectX = -1;
if (pD == "U") VectY = 1;
if (pD == "D") VectY = -1;
pNewX = pInitX + VectX * pT;
pNewY = pInitY + VectY * pT;
}
// 2点間のnormを返す
static decimal DeriveNorm(decimal pX1, decimal pY1, decimal pX2, decimal pY2)
{
decimal XDiff = pX1 - pX2;
decimal YDiff = pY1 - pY2;
return XDiff * XDiff + YDiff * YDiff;
}
}
aketijyuuzou