結果

問題 No.2564 衝突予測
ユーザー shumibakoshumibako
提出日時 2023-12-02 15:54:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 2,784 bytes
コンパイル時間 5,271 ms
コンパイル使用メモリ 242,436 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-02 15:54:34
合計ジャッジ時間 9,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cctype>
#include <string>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <atcoder/all>
#include <math.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using ll = long long;
using p = pair<int,int>;
using mod = modint998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<char,int>> RunLength(string s){
    vector<pair<char,int>> R;
    int n = s.size();
    int pre = 0;
    rep(i,n - 1){
        if(s[i + 1] != s[i]){
            R.push_back({s[i],i - pre + 1});
            pre = i + 1;
        }
    }
    if(pre != n)R.push_back({s[n - 1],n - pre});
    return R;
}

int op(int a,int b){return min(a,b);}
int e(){return (int)1e9;}
segtree<int,op,e> seg(1);

int n,m;
map<int,vector<int>> mp;
int bfs(int start,int goal){
    queue<int> Q;
    vector<int> seen(n,-1);
    Q.push(start);
    seen[start] = 0;
    while(Q.size()){
        int now = Q.front();Q.pop();
        for(int next:mp[now]){
            if(seen[next] != -1)continue;
            seen[next] = seen[now] + 1;
            Q.push(next);
            if(next == goal)Q = {};
        }
    }
    return seen[goal];
}

int main(){
    int t;cin >> t;
    while(t--){
        int x1,x2,y1,y2;
        char d1,d2;
        cin >> x1 >> y1 >> d1;
        cin >> x2 >> y2 >> d2;
        if(d1 == d2){
            cout << "No" << endl;
        }else if((d1 == 'U' && d2 == 'D') || (d1 == 'D' && d2 == 'U') || (d1 == 'L' && d2 == 'R') || (d1 == 'R' && d2 == 'L')){
            string ans = "No";
            if(d1 == 'L' && d2 == 'R' && y1 == y2 && x2 <= x1)ans = "Yes";
            if(d1 == 'R' && d2 == 'L' && y1 == y2 && x2 >= x1)ans = "Yes";
            if(d1 == 'U' && d2 == 'D' && x1 == x2 && y2 >= y1)ans = "Yes";
            if(d1 == 'D' && d2 == 'U' && x1 == x2 && y2 <= y1)ans = "Yes";
            cout << ans << endl;
        }else{
            vector<int> L{0,0};
            int k1,k2;
            if(d1 == 'R' || d1 == 'L'){
                L[0] = x2;
                L[1] = y1;

                k1 = L[0] - x1;
                k2 = L[1] - y2;
                if(d1 == 'L')k1 *= -1;
                if(d2 == 'D')k2 *= -1;
                
            }else{//d1 U or D
                L[0] = x1;
                L[1] = y2;
                k1 = L[1] - y1;
                k2 = L[0] - x2;
                if(d1 == 'D')k1 *= -1;
                if(d2 == 'L')k2 *= -1;
            }
            if(k1 >= 0 && k1 == k2){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }
}
0