結果

問題 No.2564 衝突予測
ユーザー ゆにぽけゆにぽけ
提出日時 2023-12-02 14:55:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 2,639 bytes
コンパイル時間 3,087 ms
コンパイル使用メモリ 151,276 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 14:55:52
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
void solve()
{
	int N = 2;
	map<int,vector<int>> tate[2],yoko[2],xpy[4],xmy[4];
	for(int i = 0;i < N;i++)
	{
		int x,y;
		char c;
		cin >> x >> y >> c;
		if(c == 'U') tate[0][x].push_back(y),xpy[0][x+y].push_back(x),xmy[0][x-y].push_back(x);
		else if(c == 'D') tate[1][x].push_back(y),xpy[1][x+y].push_back(x),xmy[1][x-y].push_back(x);
		else if(c == 'R') yoko[0][y].push_back(x),xpy[2][x+y].push_back(x),xmy[2][x-y].push_back(x);
		else yoko[1][y].push_back(x),xpy[3][x+y].push_back(x),xmy[3][x-y].push_back(x);
	}
	for(int i = 0;i < 2;i++)
	{
		for(auto &[x,v]:tate[i]) sort(v.begin(),v.end());
		for(auto &[y,v]:yoko[i]) sort(v.begin(),v.end());
	}
	for(int i = 0;i < 4;i++)
	{
		for(auto &[xy,v]:xpy[i]) sort(v.begin(),v.end());
		for(auto &[xy,v]:xmy[i]) sort(v.begin(),v.end());
	}
	int ans = __INT_MAX__;
	for(const auto &[x,v]:tate[0])
	{
		if(!tate[1].count(x)) continue;
		for(int y:v)
		{
			auto it = lower_bound(tate[1][x].begin(),tate[1][x].end(),y);
			if(it == tate[1][x].end()) break;
			ans = min(ans,(*it-y)*5);
		}
	}
	for(const auto &[y,v]:yoko[0])
	{
		if(!yoko[1].count(y)) continue;
		for(int x:v)
		{
			auto it = lower_bound(yoko[1][y].begin(),yoko[1][y].end(),x);
			if(it == yoko[1][y].end()) break;
			ans = min(ans,(*it-x)*5);
		}
	}
	for(const auto &[x,v]:tate[0])
	{
		for(int y:v)
		{
			if(xpy[2].count(x+y))
			{
				auto it = lower_bound(xpy[2][x+y].begin(),xpy[2][x+y].end(),x);
				if(it != xpy[2][x+y].begin())
				{
					it--;
					ans = min(ans,(x-*it)*10);
				}
			}
			if(xmy[3].count(x-y))
			{
				auto it = lower_bound(xmy[3][x-y].begin(),xmy[3][x-y].end(),x);
				if(it != xmy[3][x-y].end()) ans = min(ans,(*it-x)*10);
			}
		}
	}
	for(const auto &[x,v]:tate[1])
	{
		for(int y:v)
		{
			if(xpy[3].count(x+y))
			{
				auto it = lower_bound(xpy[3][x+y].begin(),xpy[3][x+y].end(),x);
				if(it != xpy[3][x+y].end()) ans = min(ans,(*it-x)*10);
			}
			if(xmy[2].count(x-y))
			{
				auto it = lower_bound(xmy[2][x-y].begin(),xmy[2][x-y].end(),x);
				if(it != xmy[2][x-y].begin())
				{
					it--;
					ans = min(ans,(x-*it)*10);
				}
			}
		}
	}
	if(ans == __INT_MAX__) cout << "No\n";
	else cout << "Yes" << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	while(tt--) solve();
}
0