結果

問題 No.2564 衝突予測
ユーザー Mikan04yMikan04y
提出日時 2023-12-02 16:10:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,749 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 202,552 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-02 16:10:31
合計ジャッジ時間 5,800 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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