Submission #1175526

#TimeUsernameProblemLanguageResultExecution timeMemory
1175526MuhammadSaramNaval battle (CEOI24_battle)C++20
46 / 100
3104 ms364380 KiB
#include <bits/stdc++.h>

using namespace std;

bool ty(char c)
{
	return c=='N' or c=='S';
}

int coll(int x,int y,char c,int x1,int y1,char c1)
{
	if (c==c1) return -1;
	// cout<<c<<' '<<c1<<endl;
	if (ty(c)==ty(c1))
	{
		if (ty(c))
		{
			if (c1=='N')
				swap(y,y1);
			if (x==x1 && y>y1)
				return (y-y1)/2;
			return -1;
		}
		else
		{
			if (c1=='E')
				swap(x,x1);
			if (y==y1 && x<x1)
				return (x1-x)/2;
			return -1;
		}
	}
	if (ty(c1))
		swap(x,x1),swap(y,y1),swap(c,c1);
	if (c=='N')
	{
		if(c1=='E' && x1<x && x-y==x1-y1)
			return x-x1;
		else if(c1=='W' && x1>x && x+y==x1+y1)
			return x1-x;
	}
	else if(c=='S')
	{
		if(c1=='E' && x1<x && x+y==x1+y1)
			return x-x1;
		else if(c1=='W' && x<x1 && x-y==x1-y1)
			return x1-x;
	}
	return -1;
}

int main()
{
	int n;
	cin>>n;
	int x[n],y[n];
	char c[n];
	for (int i=0;i<n;i++)
		cin>>x[i]>>y[i]>>c[i];
	map<int,vector<pair<int,int>>> edg;
	for (int i=0;i<n;i++)
		for (int j=i+1;j<n;j++)
		{
			int w=coll(x[i],y[i],c[i],x[j],y[j],c[j]);
			if (~w)
				edg[w].push_back({i,j});
		}
	bool det[n]={};
	for (auto [t,v]:edg)
	{
		set<int> se;
		for (auto [i,j]:v)
			if (!det[i] && !det[j])
				se.insert(i),se.insert(j);
		for (int i:se)
			det[i]=1;
	}
	for (int i=0;i<n;i++)
		if (!det[i])
			cout<<i+1<<endl;
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...