Submission #1080747

#TimeUsernameProblemLanguageResultExecution timeMemory
1080747ArturgoNaval battle (CEOI24_battle)C++14
6 / 100
1519 ms190368 KiB
#include <bits/stdc++.h> #define int long long using namespace std; struct Point { int x, y, dir; }; int NORD = 0, OUEST = 1, SUD = 2, EST = 3; map<char, int> to_dir = {{'N', NORD}, {'W', OUEST}, {'S', SUD}, {'E', EST}}; vector<Point> dirs = {{0, -1, NORD}, {-1, 0, OUEST}, {0, 1, SUD}, {1, 0, EST}}; pair<int, int> rotate(pair<int, int> pt) { return {pt.first + pt.second, pt.second - pt.first}; } struct Collision { int id1, id2, temps; }; bool operator < (const Collision& a, const Collision& b) { return a.temps > b.temps; } int nbPoints; vector<Point> points; vector<bool> estEnVie; struct Point1D { int id, pos, sens; }; bool operator < (const Point1D& a, const Point1D& b) { return a.pos < b.pos; } struct Diagonale { Collision suiv_collision; priority_queue<Collision> collisions; list<Point1D> elems; map<int, list<Point1D>::iterator> its; void etudie(const Point1D& a, const Point1D& b) { if(a.sens > b.sens) { collisions.push({a.id, b.id, b.pos - a.pos}); } } void update() { while(!collisions.empty()) { Collision col = collisions.top(); if(estEnVie[col.id1] && estEnVie[col.id2]) break; else collisions.pop(); } if(collisions.empty()) suiv_collision = {-1, -1, -1}; else suiv_collision = collisions.top(); } void init() { vector<Point1D> elemsVec(elems.begin(), elems.end()); sort(elemsVec.begin(), elemsVec.end()); elems = list<Point1D>(elemsVec.begin(), elemsVec.end()); for(auto it = elems.begin();it != elems.end();it++) { its[it->id] = it; if(next(it) != elems.end()) { etudie(*it, *next(it)); } } update(); } void supprimer(int id) { auto it = its[id]; auto itSuiv = elems.erase(it); if(itSuiv != elems.begin()) { auto itPrec = prev(itSuiv); etudie(*itPrec, *itSuiv); } update(); } }; vector<vector<Diagonale*>> diagonales; vector<map<int, Diagonale>> directions(4); void ajoute(int dir, int coord1, int coord2, int id, int sens) { directions[dir][coord1].elems.push_back({id, coord2, sens}); diagonales[id].push_back(&directions[dir][coord1]); } signed main() { ios_base::sync_with_stdio(false); cin >> nbPoints; estEnVie = vector<bool>(nbPoints, true); diagonales = vector<vector<Diagonale*>>(nbPoints); for(int iPoint = 0;iPoint < nbPoints;iPoint++) { int x, y; char type; cin >> x >> y >> type; points.push_back({x, y, to_dir[type]}); } for(int iPoint = 0;iPoint < nbPoints;iPoint++) { Point& p = points[iPoint]; pair<int, int> coords = rotate({p.x, p.y}); pair<int, int> dir = rotate({dirs[p.dir].x, dirs[p.dir].y}); for(int iDir = 0;iDir < 4;iDir++) { ajoute(iDir, coords.first, coords.second, iPoint, dir.second); dir = {-dir.second, dir.first}; coords = {-coords.second, coords.first}; } } priority_queue<Collision> collisions; for(int dir = 0;dir < 4;dir++) { for(auto it = directions[dir].begin();it != directions[dir].end();it++) { it->second.init(); if(it->second.suiv_collision.temps != -1) collisions.push(it->second.suiv_collision); } } while(!collisions.empty()) { vector<int> aSupprimer; int temps = collisions.top().temps; while(!collisions.empty() && collisions.top().temps == temps) { Collision col = collisions.top(); collisions.pop(); if(estEnVie[col.id1] && estEnVie[col.id2]) { aSupprimer.push_back(col.id1); aSupprimer.push_back(col.id2); } } sort(aSupprimer.begin(), aSupprimer.end()); aSupprimer.erase(unique(aSupprimer.begin(), aSupprimer.end()), aSupprimer.end()); for(int id : aSupprimer) { estEnVie[id] = false; for(Diagonale* diag : diagonales[id]) { diag->supprimer(id); } } for(int id : aSupprimer) { for(Diagonale* diag : diagonales[id]) { if(diag->suiv_collision.temps != -1) { collisions.push(diag->suiv_collision); } } } } for(int iPoint = 0;iPoint < nbPoints;iPoint++) { if(estEnVie[iPoint]) { cout << iPoint + 1 << " "; } } cout << endl; return 0; }
#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...