Submission #1084093

#TimeUsernameProblemLanguageResultExecution timeMemory
1084093MighilonNaval battle (CEOI24_battle)C++17
36 / 100
437 ms30040 KiB
#include <bits/stdc++.h> using namespace std; //#define DEBUG #ifdef DEBUG void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} template<typename T, typename V> void __print(pair<T, V> &x) {cerr << "{";__print(x.first); cerr << ", "; __print(x.second); cerr << "}";} template<typename T> void __print(T &x){cerr << "{"; int f = 0; for(auto i: x){if(f) cerr << ", ", f += 1; __print(i);} cerr << "}";} void _print() {cerr << "]\n";} template<typename T, typename... V> void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);} #define dbg(x...) cerr << "\e[91m" << __func__ << ": " << __LINE__ << "[" << #x << "] = ["; _print(x); cerr << endl; #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, int L){ 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.f, 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); int dd[4] = {0, 2, 3, 3}; F0R(i, 4){ vpi x = diagonal_compute(i, (i + 1) % 4, i % 2 == 0 ? -1 : 1, dd[i]); 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...