結果

問題 No.2564 衝突予測
ユーザー hatsuka_iwahatsuka_iwa
提出日時 2023-12-08 04:09:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 2,209 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 202,544 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-08 04:09:18
合計ジャッジ時間 6,101 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int T; cin >> T;

  //y1を上方向に
  auto check_ud = [&](int x1, int y1, int x2, int y2) {
    //y方向がy2より大きいとダメ
    if (y1 > y2 || x1 != x2) return false;
    //d2が下方向でxが違うとダメ
    //if (x1 != x2) return false;
    return true;
  };

  //x1を右方向に
  auto check_lr = [&](int x1, int y1, int x2, int y2) {
    //x方向がx2より大きいとダメ
    if (x1 > x2 || y1 != y2) return false;
    //d2が下方向でxが違うとダメ
    //if (d2 == 'D' && x1 != x2) return false;
    return true;
  };

  auto check_ulr = [&](int x1, int y1, int x2, int y2, char d2) {
    if (y1 > y2) return false;
    int diff = y2 - y1;
    if (d2 == 'L' && x1 != x2 - diff) return false;
    if (d2 == 'R' && x1 != x2 + diff) return false;
    return true;
  };

  auto check_dlr = [&](int x1, int y1, int x2, int y2, char d2) {
    if (y1 < y2) return false;
    int diff = y1 - y2;
    if (d2 == 'L' && x1 != x2 - diff) return false;
    if (d2 == 'R' && x1 != x2 + diff) return false;
    return true;
  };
  
  auto f = [&]() {
    int x1, y1, x2, y2;
    char d1, d2; cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;

    //方向が同じだとダメ
    if (d1 == d2) return false;

    //d1が上方向
    if (d1 == 'U') {
      if (d2 == 'D') return check_ud(x1, y1, x2, y2);
      if (d2 == 'L') return check_ulr(x1, y1, x2, y2, d2);
      if (d2 == 'R') return check_ulr(x1, y1, x2, y2, d2);
    }

    if (d1 == 'D') {
      if (d2 == 'U') return check_ud(x2, y2, x1, y1);
      if (d2 == 'L') return check_dlr(x1, y1, x2, y2, d2);
      if (d2 == 'R') return check_dlr(x1, y1, x2, y2, d2);
    }

    if (d1 == 'R') {
      if (d2 == 'L') return check_lr(x1, y1, x2, y2);
      if (d2 == 'U') return check_ulr(x2, y2, x1, y1, d1);
      if (d2 == 'D') return check_dlr(x2, y2, x1, y1, d1);
    }

    if (d1 == 'L') {
      if (d2 == 'R') return check_lr(x2, y2, x1, y1);
      if (d2 == 'U') return check_ulr(x2, y2, x1, y1, d1);
      if (d2 == 'D') return check_dlr(x2, y2, x1, y1, d1);
    }
    
    return true;
  };

  for (int i = 0; i < T; i++)
    cout << (f() ? "Yes" : "No") << endl;
}
0