Submission #1073992

#TimeUsernameProblemLanguageResultExecution timeMemory
1073992GrindMachineNaval battle (CEOI24_battle)C++17
6 / 100
3055 ms194092 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define conts continue #define sz(a) (int)a.size() #define ff first #define ss second #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &x, T y){ x = min(x,y); } template<typename T> void amax(T &x, T y){ x = max(x,y); } template<typename A,typename B> string to_string(pair<A,B> p); string to_string(const string &s){ return "'"+s+"'"; } string to_string(const char* s){ return to_string((string)s); } string to_string(bool b){ return b?"true":"false"; } template<typename A> string to_string(A v){ string res = "{"; trav(x,v){ res += to_string(x)+","; } if(res.back() == ',') res.pop_back(); res += "}"; return res; } template<typename A,typename B> string to_string(pair<A,B> p){ return "("+to_string(p.ff)+","+to_string(p.ss)+")"; } #define debug(x) cout << "[" << #x << "]: "; cout << to_string(x) << endl const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = 1e9 + 5; const ll inf2 = (ll)1e18 + 5; void solve(int test_case){ int n; cin >> n; vector<array<int,3>> a(n+5); rep1(i,n){ int r,c; cin >> r >> c; char ch; cin >> ch; swap(r,c); int d = -1; if(ch == 'E') d = 0; if(ch == 'W') d = 1; if(ch == 'S') d = 2; if(ch == 'N') d = 3; a[i] = {r,c,d}; } map<int,set<pii>> mpr,mpc,mpsum,mpdiff; rep1(i,n){ auto [r,c,d] = a[i]; mpr[r].insert({c,i}); mpc[c].insert({r,i}); mpsum[r+c].insert({r,i}); mpdiff[r-c].insert({r,i}); } int mnt = 2*inf1; vector<int> del; auto upd = [&](int i, int j){ if(a[i][2] > a[j][2]) swap(i,j); auto [ri,ci,di] = a[i]; auto [rj,cj,dj] = a[j]; if(di == dj) return; int t = inf1; if((di^1) == dj){ if(di == 0){ if(ri == rj and ci <= cj){ t = (cj-ci)/2; } } else{ if(ci == cj and ri <= rj){ t = (rj-ri)/2; } } } else{ if(di == 0){ if(ci <= cj){ if(dj == 2){ if(ri-rj == cj-ci){ t = abs(ri-rj); } } else{ if(rj-ri == cj-ci){ t = abs(ri-rj); } } } } else{ if(ci >= cj){ if(dj == 2){ if(ri-rj == ci-cj){ t = abs(ri-rj); } } else{ if(rj-ri == ci-cj){ t = abs(ri-rj); } } } } } if(t > mnt) return; if(t < mnt){ del.clear(); } mnt = t; del.pb(i), del.pb(j); }; vector<bool> rem(n+5); while(true){ mnt = 2*inf1; del.clear(); for(auto &mp : {mpr,mpc,mpsum,mpdiff}){ for(auto &[val,st] : mp){ for(auto [c1,i] : st){ for(auto [c2,j] : st){ if(i == j) conts; upd(i,j); } } } } if(mnt == 2*inf1) break; trav(i,del){ rem[i] = 1; auto [r,c,d] = a[i]; mpr[r].erase({c,i}); mpc[c].erase({r,i}); mpsum[r+c].erase({r,i}); mpdiff[r-c].erase({r,i}); } } vector<int> ans; rep1(i,n){ if(!rem[i]){ ans.pb(i); } } trav(x,ans) cout << x << endl; } int main(){ fastio; int t = 1; // cin >> t; rep1(i,t){ solve(i); } 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...