Submission #1050854

#TimeUsernameProblemLanguageResultExecution timeMemory
1050854n1kNaval battle (CEOI24_battle)C++17
0 / 100
3063 ms57680 KiB
#include <bits/stdc++.h>

#if defined(LOCAL)
#include "debug.cpp"
#else
#define debug(x...) 0
#endif // LOCAL

using namespace std;

using ll = long long;

#define all(a) (a).begin(), (a).end()

void umax(ll &a, ll b){
	a = max(a, b);
}

void solve(){
	int n; cin >> n;
	vector<int> r(n), c(n);
	vector<char> d(n);
	vector<int> dead(n);
	map<int, set<pair<int, int>>> d1;
	set<array<int, 3>> pq;
	for(int i=0; i<n; i++){
		cin >> r[i] >> c[i] >> d[i];
		d1[r[i]+c[i]].insert({r[i], i});
	}
	for(auto [id, v]:d1){
		for(auto it=v.begin(); next(it)!=v.end(); it++){
			auto [r1, i1]=*it;
			auto [r2, i2]=*next(it);
			if(d[i1]!=d[i2]){
				pq.insert({abs(r[i1]-r[i2]), i1, i2});
			}
		}
		debug(id, v);
	}
	auto remove = [&](int i){
		dead[i]=1;
		auto it = d1[r[i]+c[i]].lower_bound({r[i], i});
		int il = -1, ir = -1;
		if(next(it)!=d1[r[i]+c[i]].end()){
			auto [_, i2] = *next(it);
			pq.erase({abs(r[i]-r[i2]), i, i2});
			ir=i2;
		}
		if(it!=d1[r[i]+c[i]].begin()){
			auto [_, i2] = *prev(it);
			pq.erase({abs(r[i]-r[i2]), i2, i});
			il=i2;
		}
		d1[r[i]+c[i]].erase(it);
		if(il!=-1 and ir!=-1){
			pq.insert({abs(r[il]-r[ir]), il, ir});
		}
	};
	while(pq.size()){
		debug(pq);
		vector<array<int, 3>> cur = {*pq.begin()};
		pq.erase(pq.begin());
		while(pq.size() and pq.begin()->front() == cur.front().front()){
			cur.push_back(*pq.begin());
			pq.erase(pq.begin());
		}
		debug(cur);
		// remove all ships that colide
		for(auto [t, i1, i2]:cur){
			debug(t, i1, i2);
			remove(i1);
			remove(i2);
		}
	}
	debug(dead);
	for(int i=0; i<n; i++){
		if(dead[i]) continue;
		cout << i + 1<< endl;
	}
}

int main(){
	solve();
	return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:6:21: warning: statement has no effect [-Wunused-value]
    6 | #define debug(x...) 0
      |                     ^
Main.cpp:38:3: note: in expansion of macro 'debug'
   38 |   debug(id, v);
      |   ^~~~~
Main.cpp:6:21: warning: statement has no effect [-Wunused-value]
    6 | #define debug(x...) 0
      |                     ^
Main.cpp:60:3: note: in expansion of macro 'debug'
   60 |   debug(pq);
      |   ^~~~~
Main.cpp:6:21: warning: statement has no effect [-Wunused-value]
    6 | #define debug(x...) 0
      |                     ^
Main.cpp:67:3: note: in expansion of macro 'debug'
   67 |   debug(cur);
      |   ^~~~~
Main.cpp:6:21: warning: statement has no effect [-Wunused-value]
    6 | #define debug(x...) 0
      |                     ^
Main.cpp:70:4: note: in expansion of macro 'debug'
   70 |    debug(t, i1, i2);
      |    ^~~~~
Main.cpp:6:21: warning: statement has no effect [-Wunused-value]
    6 | #define debug(x...) 0
      |                     ^
Main.cpp:75:2: note: in expansion of macro 'debug'
   75 |  debug(dead);
      |  ^~~~~
#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...