Submission #1040824

#TimeUsernameProblemLanguageResultExecution timeMemory
1040824elazarkorenNaval battle (CEOI24_battle)C++17
36 / 100
782 ms89420 KiB
#include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vii; typedef vector<bool> vb; const int MAX_N = 2e5 + 5; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; int mptype[200]; int x[MAX_N], y[MAX_N], type[MAX_N]; int Crash(int i, int j) { if (type[i] == type[j]) return -1; if (type[i] > type[j]) swap(i, j); if (!type[i] && type[j] == 1) { if (x[i] != x[j] || y[i] > y[j]) return -1; return (y[j] - y[i]) / 2; } if (!type[i] && type[j] == 2) { if (x[i] + y[i] != x[j] + y[j] || x[i] < x[j]) return -1; return x[i] - x[j]; } if (!type[i] && type[j] == 3) { if (x[i] - y[i] != x[j] - y[j] || x[i] > x[j]) return -1; return x[j] - x[i]; } if (type[i] == 1 && type[j] == 2) { if (x[i] - y[i] != x[j] - y[j] || x[i] < x[j]) return -1; return x[i] - x[j]; } if (type[i] == 1 && type[j] == 3) { if (x[i] + y[i] != x[j] + y[j] || x[i] > x[j]) return -1; return x[j] - x[i]; } if (y[i] != y[j] || x[i] > x[j]) return -1; return (x[j] - x[i]) / 2; } priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq; void Erase(set<pii> &s, pii p) { auto it = s.erase(s.find(p)); if (it == s.end() || it == s.begin()) return; auto it2 = it--; int i = it->y, j = it2->y; int t = Crash(i, j); if (t != -1) pq.push({t, {i, j}}); } map<int, set<pii>> rows, cols, digp[2], digm[2]; void Erase(int i) { int t = type[i]; if (!t) { Erase(cols[y[i]], {x[i], i}); Erase(digp[0][x[i] + y[i]], {x[i], i}); Erase(digm[0][x[i] - y[i]], {x[i], i}); } else if (t == 1) { Erase(cols[y[i]], {x[i], i}); Erase(digp[1][x[i] + y[i]], {x[i], i}); Erase(digm[1][x[i] - y[i]], {x[i], i}); } else if (t == 2) { Erase(rows[x[i]], {y[i], i}); Erase(digp[0][x[i] + y[i]], {x[i], i}); Erase(digm[1][x[i] - y[i]], {x[i], i}); } else { Erase(rows[x[i]], {y[i], i}); Erase(digp[1][x[i] + y[i]], {x[i], i}); Erase(digm[0][x[i] - y[i]], {x[i], i}); } } int crash_t[MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); mptype['S'] = 0, mptype['N'] = 1, mptype['E'] = 2, mptype['W'] = 3; int n; cin >> n; for (int i = 0; i < n; i++) { char t; cin >> x[i] >> y[i] >> t; type[i] = mptype[t]; } for (int i = 0; i < n; i++) { int t = type[i]; if (!t) { cols[y[i]].insert({x[i], i}); digp[0][x[i] + y[i]].insert({x[i], i}); digm[0][x[i] - y[i]].insert({x[i], i}); } else if (t == 1) { cols[y[i]].insert({x[i], i}); digp[1][x[i] + y[i]].insert({x[i], i}); digm[1][x[i] - y[i]].insert({x[i], i}); } else if (t == 2) { rows[x[i]].insert({y[i], i}); digp[0][x[i] + y[i]].insert({x[i], i}); digm[1][x[i] - y[i]].insert({x[i], i}); } else { rows[x[i]].insert({y[i], i}); digp[1][x[i] + y[i]].insert({x[i], i}); digm[0][x[i] - y[i]].insert({x[i], i}); } } for (auto &[x, s] : rows) { for (auto it = s.begin(); it != s.end();) { auto it2 = it++; if (it == s.end()) break; int i = it->y, j = it2->y; int t = Crash(i, j); if (t != -1) pq.push({t, {i, j}}); } } for (auto &[x, s] : cols) { for (auto it = s.begin(); it != s.end();) { auto it2 = it++; if (it == s.end()) break; int i = it->y, j = it2->y; int t = Crash(i, j); if (t != -1) pq.push({t, {i, j}}); } } for (int a = 0; a < 2; a++) { for (auto &[x, s] : digp[a]) { for (auto it = s.begin(); it != s.end();) { auto it2 = it++; if (it == s.end()) break; int i = it->y, j = it2->y; int t = Crash(i, j); if (t != -1) pq.push({t, {i, j}}); } } } for (int a = 0; a < 2; a++) { for (auto &[x, s] : digm[a]) { for (auto it = s.begin(); it != s.end();) { auto it2 = it++; if (it == s.end()) break; int i = it->y, j = it2->y; int t = Crash(i, j); if (t != -1) pq.push({t, {i, j}}); } } } while (!pq.empty()) { auto [t, q] = pq.top(); pq.pop(); auto [i, j] = q; if (crash_t[j]) swap(i, j); if (crash_t[j]) continue; if (!crash_t[i]) { crash_t[i] = crash_t[j] = t; Erase(i), Erase(j); } else if (crash_t[i] == t) { crash_t[j] = t; Erase(j); } } // vector<pair<int, pii>> events; //{{time, {x, y}}, {s1, s2}} // for (int i = 0; i < n; i++) { // for (int j = i + 1; j < n; j++) { // auto p = Crash(i, j); // if (p == -1) continue; // events.push_back({p, {i, j}}); // } // } // sort(all(events)); // for (auto [t, q] : events) { // auto [i, j] = q; // if (crash_t[j]) swap(i, j); // if (crash_t[j]) continue; // if (!crash_t[i]) { // crash_t[i] = crash_t[j] = t; // } else if (crash_t[i] == t) { // crash_t[j] = t; // } // } for (int i = 0; i < n; i++) { if (!crash_t[i]) cout << i + 1 << '\n'; } } /* 2 2 2 W 0 4 N */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:96:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   96 |         type[i] = mptype[t];
      |                          ^
#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...