結果

問題 No.2564 衝突予測
ユーザー lemon_math_tealemon_math_tea
提出日時 2023-12-02 16:06:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 349 ms / 2,000 ms
コード長 4,896 bytes
コンパイル時間 4,794 ms
コンパイル使用メモリ 277,920 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 16:07:06
合計ジャッジ時間 8,631 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// コンパイルはctrl + shift + B
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define yes "Yes"
#define no "No"

// 最大公約数 O(log(N))
template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

// 素数判定 O(sqrt(N))
bool is_prime(ll n) {
    for (ll i = 2; i*i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

//n以下の素数求めマシーン O(Nloglog(N))
vector<ll> getprime(ll n) {
    vector<ll> ans;
    vector<bool> isprime(n + 1, true);
    //0, 1はダメ
    isprime[0] = false; isprime[1] = false;

    //やる
    for (int i = 2; i <= n; i++) {
        if (!isprime[i]) continue;
        ans.push_back(i);

        for (int j =  2 * i; j <= n; j += i) {
            //i以外のiの倍数をキャンセル
            isprime[j] = false;
        }
    }
    return ans;
}

// nを素因数分解 O(sqrt(N))
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> ans;
    for (ll i = 2; i*i <= n; i++) {
        if (n % i != 0) continue;
        ll e = 0;
        while (n % i == 0) {
            e++;
            n /= i;
        }
        ans.push_back({i, e});
    }
    if (n != 1) ans.push_back({n, 1});
    return ans;
}

// 各n以下の最小の素因数 O(NlogN)
vector<ll> smallest_prime(ll n) {
    vector<ll> spf(n+1);
    for (ll i = 0; i <= n; i++) spf[i] = i; //初期化
    for (ll i = 2; i+i <= n; i++) {
        if (spf[i] == i) {
            for (ll j = i*i; j <= n; j += i) {
                if (spf[j] == j) spf[j] = i;
            }
        }
    }
    return spf;
}

// 以下、コードを記すのである。

// using mint = modint998244353;
using mint = modint1000000007;

int main() {
    int t; cin >> t;
    while (t--) {
        vector<vector<int>> pos(2, vector<int>(2));
        vector<char> c(2);
        for (int i = 0; i < 2; i++) {
            cin >> pos[i][0] >> pos[i][1] >> c[i];
        }
        map<char, int> mp;
        mp['U'] = 1;
        mp['D'] = 1;
        if (c[0] == c[1]) cout << no << endl;
        else {
            if (mp[c[0]] == mp[c[1]]) {
                if (pos[0][1-mp[c[0]]] != pos[1][1-mp[c[1]]]) cout << no << endl;
                else {
                    if (c[0] == 'R') {
                        if (pos[0][mp[c[0]]] < pos[1][mp[c[1]]]) cout << yes << endl;
                        else cout << no << endl;
                    }
                    if (c[0] == 'L') {
                        if (pos[0][mp[c[0]]] > pos[1][mp[c[1]]]) cout << yes << endl;
                        else cout << no << endl;
                    }
                    if (c[0] == 'U') {
                        if (pos[0][mp[c[0]]] < pos[1][mp[c[1]]]) cout << yes << endl;
                        else cout << no << endl;
                    }
                    if (c[0] == 'D') {
                        if (pos[0][mp[c[0]]] > pos[1][mp[c[1]]]) cout << yes << endl;
                        else cout << no << endl;
                    }
                }
            }
            else {
                if (pos[0][0] == pos[1][0] || pos[0][1] == pos[1][1]) cout << no << endl;
                else {
                    int diffx = pos[1][0] - pos[0][0];
                    int diffy = pos[1][1] - pos[0][1];
                    if (abs(diffx) != abs(diffy)) cout << no << endl;
                    else {
                        if (c[0] == 'R' && diffx > 0) {
                            if ((diffy > 0 && c[1] == 'D') || (diffy < 0 && c[1] == 'U')) {
                                cout << yes << endl;
                            }
                            else cout << no << endl;
                        }
                        else if (c[0] == 'L' && diffx < 0) {
                            if ((diffy > 0 && c[1] == 'D') || (diffy < 0 && c[1] == 'U')) {
                                cout << yes << endl;
                            }
                            else cout << no << endl;
                        }
                        else if (c[0] == 'U' && diffy > 0) {
                            if ((diffx > 0 && c[1] == 'L') || (diffx < 0 && c[1] == 'R')) {
                                cout << yes << endl;
                            }
                            else cout << no << endl;
                        }
                        else if (c[0] == 'D' && diffy < 0) {
                            if ((diffx > 0 && c[1] == 'L') || (diffx < 0 && c[1] == 'R')) {
                                cout << yes << endl;
                            }
                            else cout << no << endl;
                        }
                        else cout << no << endl;
                        
                    }
                }
            }
        }
    }
}
0