제출 #1134262

#제출 시각아이디문제언어결과실행 시간메모리
1134262amunduzbaevNaval battle (CEOI24_battle)C++20
6 / 100
505 ms1114112 KiB
#include "bits/stdc++.h"

using namespace std;

//~ #define int ll
typedef long long ll;
#define ar array

template<class T> bool umin(T& a, T b) { if(b < a) { a = b; return true; } return false; }
template<class T> bool umax(T& a, T b) { if(a < b) { a = b; return true; } return false; }

//~ const int mod = 1e9 + 7;
//~ void add(int& a, const int b){
	//~ a += b;
	//~ while(a >= mod) a -= mod;
	//~ while(a < 0) a += mod;
//~ }

const int inf = 1e9 + 5;

void solve(){
	int n; cin >> n;
	
	vector<int> x(n), y(n), d(n);
	
	//~ int ch[4][2] = {
		//~ {-1, 0},
		//~ {0, 1},
		//~ {1, 0},
		//~ {0, -1}
	//~ };
	
	vector<ar<int, 2>> coll[2] = {
		{ {0, 3}, {1, 2} },
		{ {2, 3}, {1, 0} }
	};
	
	for(int i=0;i<n;i++){
		char c;
		cin >> x[i] >> y[i] >> c;
		
		//~ switch (c){
			//~ case 'N' : { d[i] = 0; }
			//~ case 'E' : { d[i] = 1; }
			//~ case 'S' : { d[i] = 2; }
			//~ case 'W' : { d[i] = 3; }
		//~ }
		
		if(c == 'N') d[i] = 0;
		if(c == 'E') d[i] = 1;
		if(c == 'S') d[i] = 2;
		if(c == 'W') d[i] = 3;
	}
	
	auto check = [&](int i, int j){
		if(x[i] > x[j]) swap(i, j);
		if(x[i] == x[j] && y[i] > y[j]) swap(i, j);
		
		//~ cout<<i<<" "<<j<<" "<<d[i]<<" "<<d[j]<<"\n";
		if((d[i] ^ d[j]) & 1){
			ar<int, 2> d_ = {d[i], d[j]};
			int dis = abs(x[i] - x[j]);
			//~ cout<<i<<" "<<j<<" "<<d_[0]<<" "<<d_[1]<<" "<<x[i]<<" "<<y[i]<<" "<<x[j]<<" "<<y[j]<<endl;
			if(x[i] + y[i] == x[j] + y[j] && (d_ == coll[0][0] || d_ == coll[0][1])){
				return dis;
			}
			if(x[i] - y[i] == x[j] - y[j] && (d_ == coll[1][0] || d_ == coll[1][1])) {
				return dis;
			}
			
			return inf;
		} else {
			if(d[i] == d[j]) return inf;
			int dis = max(abs(x[i] - x[j]), abs(y[i] - y[j]));
			if((d[i] & 1) && y[i] == y[j] && !(dis & 1)) return dis / 2;
			if(!(d[i] & 1) && x[i] == x[j] && !(dis & 1)) return dis / 2;
			return inf;
		}
	};
	
	vector<vector<int>> t(n, vector<int>(n, inf));
	vector<ar<int, 3>> colt;
	
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			t[i][j] = check(i, j);
			
			if(t[i][j] < inf) colt.push_back({t[i][j], i, j});
		}
	}
	
	//~ for(int i=0;i<n;i++){
		//~ for(int j=0;j<n;j++){
			//~ if(t[i][j] < inf) cout<<i<<" "<<j<<" "<<t[i][j]<<"\n";
		//~ }
	//~ }
	
	sort(colt.begin(), colt.end());
	
	vector<int> liv(n, 1);
	for(int i=0;i<(int)colt.size();){
		int j = i;
		while(j < (int)colt.size() && colt[j][0] == colt[i][0]) j++;
		
		vector<int> dead;
		for(int k=i;k<j;k++){
			auto [time_, x, y] = colt[k];
			
			if(liv[x] && liv[y]){
				dead.push_back(x);
				dead.push_back(y);
			}
		}
		
		//~ cout<<colt[i][0]<<" : ";
		for(auto x : dead){
			//~ cout<<x<<" ";
			liv[x] = 0;
		}
		//~ cout<<"\n";
		
		i = j;
	}
	
	for(int i=0;i<n;i++){
		if(liv[i]) cout<<i + 1<<"\n";
	}
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int t = 1;
	
	//~ cin >> t;
	while(t--){
		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...