Submission #1134352

#TimeUsernameProblemLanguageResultExecution timeMemory
1134352NurislamNaval battle (CEOI24_battle)C++20
46 / 100
2482 ms1114112 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)

const int inf = 1e18;
void solve(){
	int n;
	cin >> n;
	vector<array<int,4>> v;
	map<char,int> mp;
	mp['N'] = 0;mp['E'] = 1;mp['S'] = 2;mp['W'] = 3;
	
	vector<int> dx {0, 1, 0, -1};
	vector<int> dy {-1, 0, 1, 0};
	
	for(int i = 0; i < n; i++){
		int x, y; char d;
		cin >> x >> y >> d;
		x ++ , y ++ ;
		v.push_back({x, y, i, mp[d]});
	}
	vector<array<int,3>> ds;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			int nw = abs(v[i][0] - v[j][0]) + abs(v[i][1] - v[j][1]);
			bool bomb = 0;
			if(abs(v[i][0] - v[j][0]) == 0 || abs(v[i][1] - v[j][1]) == 0)bomb = 1;
			if(abs(v[i][0] - v[j][0]) == abs(v[i][1] - v[j][1]))bomb = 1;
			//cout << i+1 << ' ' << j+1 << ' ' << bomb << '\n';
			if(!bomb)continue;
			if(v[i][3] == 0){
				if(v[j][3] == 1)
					if(v[j][0] < v[i][0] && v[i][1] > v[j][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 2)
					if(v[j][0] == v[i][0] && v[i][1] > v[j][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 3)
					if(v[j][0] > v[i][0] && v[i][1] > v[j][1])ds.pb({nw/2, i, j});
			}
			if(v[i][3] == 1){
				if(v[j][3] == 0)
					if(v[i][0] < v[j][0] && v[i][1] < v[j][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 2)
					if(v[i][0] < v[j][0] && v[i][1] > v[j][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 3)
					if(v[i][0] < v[j][0] && v[i][1] == v[j][1])ds.pb({nw/2, i, j});
			}
			if(v[i][3] == 2){
				if(v[j][3] == 0)
					if(v[j][0] == v[i][0] && v[j][1] > v[i][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 1)
					if(v[j][0] < v[i][0] && v[j][1] > v[i][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 3)
					if(v[j][0] > v[i][0] && v[j][1] > v[i][1])ds.pb({nw/2, i, j});
			}
			if(v[i][3] == 3){
				if(v[j][3] == 0)
					if(v[i][0] > v[j][0] && v[j][1] > v[i][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 1)
					if(v[i][0] > v[j][0] && v[i][1] == v[j][1])ds.pb({nw/2, i, j});
				if(v[j][3] == 2)
					if(v[i][0] > v[j][0] && v[j][1] < v[i][1])ds.pb({nw/2, i, j});
			}
		}
	}
	
	sort(all(ds));
	vector<int> mn(n+1, inf), oldi(n, 0);
	for(auto [nw, i, j]:ds){
		
		if((mn[i] == inf || mn[i] == nw) && (mn[j] == nw||mn[j] == inf)){
			oldi[i] = oldi[j] = 1;
			mn[i] = mn[j] = nw;
		}
	}
	for(int i = 0; i < n; i++){
		if(oldi[i])continue;
		cout << i+1 << '\n';
	}
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    };
}














#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...