Submission #1137578

#TimeUsernameProblemLanguageResultExecution timeMemory
1137578Faisal_SaqibNaval battle (CEOI24_battle)C++20
6 / 100
48 ms2628 KiB
//
// Created by faisal-saqib on 10:22 AM 1/20/25.
//
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define int long long
const int N=1e5+10;
struct  {
	int x,y;
	char d;
} ship[N];
int32_t main() {
	int tas=1;
	// cin>>tas;
	while (tas--) {
		int n;
		cin>>n;
		for(int i=0;i<n;i++) {
			cin>>ship[i].x>>ship[i].y>>ship[i].d;
			// ship[i].x=1e9-ship[i].x;
			// ship[i].y=1e9-ship[i].y;
		}
		// cout<<"AT "<<ship[0].d<<' '<<ship[1].d<<endl;
		// bool subtask5=1,subtask1=0;
		// if (subtask1) {
		// 	bool alive[n+1]={1};
		// 	for (int i=0;i<n;i++)alive[i]=1;
		// 	int MX=2e5;
		// 	for (int t=1;t<=MX;t++) {
		// 		map<pair<int,int>,int>mp;
		// 		for (int i=0;i<n;i++) {
		// 			if (!alive[i])continue;
		// 			if (ship[i].d=='N') {
		// 				ship[i].y--;
		// 			}else if (ship[i].d=='S') {
		// 				ship[i].y++;
		// 			}else if (ship[i].d=='E') {
		// 				ship[i].x++;
		// 			}
		// 			else {
		// 				ship[i].x--;
		// 			}
		// 			if (mp.find({ship[i].x,ship[i].y})==mp.end()) {
		// 				mp[{ship[i].x,ship[i].y}]=i;
		// 			}
		// 			else {
		// 				alive[i]=0;
		// 				alive[mp[{ship[i].x,ship[i].y}]]=0;
		// 			}
		// 		}
		// 	}
		// 	for (int i=0;i<n;i++)if(alive[i])cout<<i+1<<endl;;
		// }
		// Subtask 1-5
		// if (subtask5)
		{
			vector<vector<int>> col;
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(i==j)continue;
					// N,W = negative direction
					// i-j

					//S,W = positive direction
					if (ship[i].d == 'N' && ship[j].d == 'S') { // OK
						if (ship[i].x == ship[j].x && ship[i].y > ship[j].y) {
							int time = (ship[i].y - ship[j].y) / 2;
							if ((ship[i].y - ship[j].y) % 2 == 0) {
								col.push_back({time, i, j});
							}
						}
					} else if (ship[i].d == 'N' && ship[j].d == 'E') {//OK
						int dx = ship[i].x - ship[j].x;
						int dy = ship[i].y - ship[j].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					} else if (ship[i].d == 'N' && ship[j].d == 'W') {//OK
						int dx = ship[j].x - ship[i].x;
						int dy = ship[i].y - ship[j].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					}


					else if (ship[i].d == 'S' && ship[j].d == 'N') {//OK
						if (ship[i].x == ship[j].x && ship[i].y < ship[j].y) {
							int time = (ship[j].y - ship[i].y) / 2;
							if ((ship[j].y - ship[i].y) % 2 == 0) {
								col.push_back({time, i, j});
							}
						}
					} else if (ship[i].d == 'S' && ship[j].d == 'W') {//OK
						int dx = ship[j].x - ship[i].x;
						int dy = ship[j].y - ship[i].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					}  else if (ship[i].d == 'S' && ship[j].d == 'E') {//OK
						int dx = ship[i].x - ship[j].x;
						int dy = ship[j].y - ship[i].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					}


					else if (ship[i].d == 'E' && ship[j].d == 'W') {//OK
						if (ship[i].y == ship[j].y && ship[i].x < ship[j].x) {
							int time = (ship[i].x - ship[j].x) / 2;
							if ((ship[i].x - ship[j].x) % 2 == 0) {
								col.push_back({time, i, j});
							}
						}
					} else if (ship[i].d == 'E' && ship[j].d == 'N') {//OK
						int dx = ship[j].x - ship[i].x;
						int dy = ship[j].y - ship[i].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					} else if (ship[i].d == 'E' && ship[j].d == 'S') {//OK
						int dx = ship[j].x - ship[i].x;
						int dy = ship[i].y - ship[j].y;
						// cout<<"Hola "<<i<<' '<<j<<' '<<dx<<' '<<dy<<endl;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					}


					else if (ship[i].d == 'W' && ship[j].d == 'E') {//OK
						if (ship[i].y == ship[j].y && ship[i].x > ship[j].x) {
							int time = (ship[j].x - ship[i].x) / 2;
							if ((ship[j].x - ship[i].x) % 2 == 0) {
								col.push_back({time, i, j});
							}
						}
					} else if (ship[i].d == 'W' && ship[j].d == 'S') {//OK
						int dx = ship[i].x - ship[j].x;
						int dy = ship[i].y - ship[j].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					} //Done before
					 else if (ship[i].d == 'W' && ship[j].d == 'N') {//OK
						int dx = ship[i].x - ship[j].x;
						int dy = ship[j].y - ship[i].y;
						if (dx > 0 && dy > 0 && dx == dy) {
							col.push_back({dx, i, j});
						}
					}
				}
			}
			sort(begin(col),end(col));
			// cout<<"ALL collisions:"<<endl;
			// for (auto it:col) {
			// 	cout<<it[0]<<' '<<it[1]<<' '<<it[2]<<endl;
			// }
			// cout<<endl;
			bool alive[n+1]={1};
			for (int i=0;i<n;i++)alive[i]=1;
			for(int i=0;i<col.size();) {
				vector<int> dead;
				int c=0;
				for (int j=i;j<col.size() and col[j][0]==col[i][0];j++) {
					// cout<<"Collision "<<col[i][0]<<' '<<col[i][1]<<' '<<col[i][2]<<endl;
					if (alive[col[j][1]] && alive[col[j][2]]) {
						dead.push_back(col[j][1]);
						dead.push_back(col[j][2]);
					}
					c++;
				}
				for (int j=0;j<dead.size();j++)alive[dead[j]]=0;
				i+=c;
			}
			vector<int> left;
			for (int i=0;i<n;i++)if(alive[i])left.push_back(i);
			for (int i=0;i<left.size();i++)cout<<left[i]+1<<endl;
		}
	}
}
#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...