結果

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

ソースコード

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' && abs(y1 - y2) % 2 == 0)
                ans = "Yes";
            else if (y1 > y2 && d1 == 'D' && d2 == 'U' && abs(y1 - y2) % 2 == 0)
                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 tx = abs(x1 - x2), ty = abs(y1 - y2);
            if (tx == ty)
            {
                long long cx1, cx2, cy1, cy2;
                cx1 = x1 + tx * dx[d_idx1];
                cy1 = y1 + ty * dy[d_idx1];
                cx2 = x2 + tx * dx[d_idx2];
                cy2 = y2 + ty * dy[d_idx2];
                // cout << cx1 << ", " << cy1 << endl;
                // cout << cx2 << ", " << cy2 << endl;
                if (cx1 == cx2 && cy1 == cy2)
                    ans = "Yes";
                else
                    ans = "No";
            }
            else
                ans = "No";
        }

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