結果

問題 No.2564 衝突予測
ユーザー Mikan04y
提出日時 2023-12-02 16:10:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,749 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 195,000 KB
最終ジャッジ日時 2025-02-18 05:14:53
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int index(char dir)
{
    if (dir == 'R')
        return 0;
    else if (dir == 'U')
        return 1;
    else if (dir == 'L')
        return 2;
    else
        return 3;
}

int main()
{
    int T;
    cin >> T;
    for (int t = 0; t < T; t++)
    {
        // input
        int x1, x2, y1, y2;
        char d1, d2;
        cin >> x1 >> y1 >> d1;
        cin >> x2 >> y2 >> d2;

        // main
        string ans;
        if (x1 == x2)
        {
            if (y1 < y2 && d1 == 'U' && d2 == 'D')
                ans = "Yes";
            else if (y1 > y2 && d1 == 'D' && d2 == 'U')
                ans = "Yes";
            else
                ans = "No";
        }
        else if (y1 == y2)
        {
            if (x1 < x2 && d1 == 'R' && d2 == 'L')
                ans = "Yes";
            else if (x1 > x2 && d1 == 'L' && d2 == 'R')
                ans = "Yes";
            else
                ans = "No";
        }
        else
        {
            int d_idx1 = index(d1), d_idx2 = index(d2);
            int t1 = abs(x1 - x2), t2 = abs(y1 - y2);
            if (t1 == t2)
            {
                int cx1, cx2, cy1, cy2;
                cx1 = x1 + t1 * dx[d_idx1];
                cy1 = y1 + t2 * dy[d_idx1];
                cx2 = x2 + t1 * dx[d_idx2];
                cy2 = y2 + t2 * dy[d_idx2];
                // cout << cx1 << ", " << cy1 << endl;
                // cout << cx2 << ", " << cy2 << endl;
                if (cx1 == cx2 && cy1 == cy2)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }

        // output
        cout << ans << endl;
    }
}
0