제출 #1084082

#제출 시각아이디문제언어결과실행 시간메모리
1084082MighilonNaval battle (CEOI24_battle)C++17
30 / 100
427 ms30140 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "../Library/debug.h" #else #define dbg(x...) #endif typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) for (int i = 0; i < (a); ++i) #define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i) #define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i) #define trav(a, x) for (auto& a : x) #define f first #define s second #define pb push_back #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() const char nl = '\n'; const int INF = 1e9; const int MOD = 1e9 + 7; struct point{ int x, y, d; }; vector<point> p; int n; int distance(point a, point b){ return abs(a.y - b.y) + abs(a.x - b.x); } int distance(pi a){ return distance(p[a.f], p[a.s]); } vpi diagonal_compute(int l, int r, int x){ map<int, vi> mp; dbg(l, r, x) F0R(i, n){ if(p[i].d == l || p[i].d == r){ dbg(i) mp[p[i].x + p[i].y * x].pb(i); } } trav(k, mp){ sort(all(k.s), [&](int i, int j){return p[i].x - p[i].y * x < p[j].x - p[j].y * x;}); dbg(k.s) } vpi ans; trav(i, mp){ stack<int> st; trav(j, i.s){ if(p[j].d == l) st.push(j); else if(!st.empty()){ dbg(1) ans.pb({st.top(), j}); st.pop(); } } } dbg(ans) return ans; } vpi front_front(){ vpi ans; { map<int, vi> mp; F0R(i, n){ if(p[i].d == 0 || p[i].d == 2){ mp[p[i].x].pb(i); } } trav(i, mp){ sort(all(i.s), [&](int a, int b){return p[a].y < p[b].y;}); stack<int> st; trav(j, i.s){ if(p[j].d == 0) st.push(j); else if(!st.empty()){ ans.pb({st.top(), j}); st.pop(); } } } } { map<int, vi> mp; F0R(i, n){ if(p[i].d == 1 || p[i].d == 3){ mp[p[i].y].pb(i); } } trav(i, mp){ sort(all(i.s), [&](int a, int b){return p[a].x < p[b].x;}); stack<int> st; trav(j, i.s){ if(p[j].d == 3) st.push(j); else if(!st.empty()){ ans.pb({st.top(), j}); st.pop(); } } } } dbg(ans) return ans; } void solve(){ cin >> n; p.resize(n); F0R(i, n){ char c; cin >> p[i].x >> p[i].y >> c; if(c == 'S') p[i].d = 0; else if(c == 'W') p[i].d = 1; else if(c == 'N') p[i].d = 2; else p[i].d = 3; } auto comp = [&](pi a, pi b){return distance(a) < distance(b);}; priority_queue<pi, vector<pi>, decltype(comp)> pq(comp); F0R(i, 4){ vpi x = diagonal_compute(i, (i + 1) % 4, i % 2 == 0 ? -1 : 1); dbg(x) trav(j, x) pq.push(j); } vpi x = front_front(); dbg(x) trav(j, x) pq.push(j); vi dist(n, -1); while(!pq.empty()){ auto [i, j] = pq.top(); dbg(i, j) pq.pop(); int d = distance({i, j}); if((dist[i] == -1 || dist[i] == d) && (dist[j] == -1 || dist[j] == d)){ dist[i] = d; dist[j] = d; } } F0R(i, n) if(dist[i] == -1) cout << i + 1 << nl; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int TC = 1; // cin >> TC; while(TC--){ solve(); } 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...