제출 #758041

#제출 시각아이디문제언어결과실행 시간메모리
758041DexvaTowers (NOI22_towers)C++14
5 / 100
2050 ms117168 KiB
#include <bits/stdc++.h> using namespace std; #define lln long long void solve() { lln n; cin >> n; vector< pair<lln, lln> > points; map<lln, vector<lln> > xs; //for each map<lln, vector<lln> > ys; map<lln, lln> xt; map<lln, lln> yt; for (lln i=0;i<n;i++) { lln x, y; cin >> x >> y; if (xs.find(x) != xs.end()) xs[x].push_back(i); else { vector<lln> nx; nx.push_back(i); xs[x] = nx; } if (ys.find(y) != ys.end()) ys[y].push_back(i); else { vector<lln> ny; ny.push_back(i); ys[y] = ny; } points.push_back(make_pair(x,y)); } // for (const auto& x : xs) { // vector<lln> xentry = x.second; // cout << x.first << " | "; // for (lln i=0;i<xentry.size();i++) cout << xentry[i] << " "; // cout << '\n'; // } // for (const auto& x : ys) { // vector<lln> xentry = x.second; // cout << x.first << " | "; // for (lln i=0;i<xentry.size();i++) cout << xentry[i] << " "; // cout << '\n'; // } string ans = ""; for (lln i=0;i<n;i++) { lln x = get<0>(points[i]), y = get<1>(points[i]); //check the points on the same row (i.e., same y-value) as i, is i the one with least x or most x? vector<lln> row = ys[y]; lln minx = i, maxx = i; for (const auto& p : row) { if (get<0>(points[p])<get<0>(points[minx])) minx = p; if (get<0>(points[p])>get<0>(points[maxx])) maxx = p; } //check the points on the same column (i.e., same x-value) as i, is i the one with least y or most y? vector<lln> col = xs[x]; lln miny = i, maxy = i; for (const auto& p : col) { if (get<1>(points[p])<get<1>(points[miny])) miny = p; if (get<1>(points[p])>get<1>(points[maxy])) maxy = p; } // cout << "Point " << i << " " << minx << " " << maxx << " " << miny << " " << maxy << '\n'; if ((minx==i && miny==i) || (minx==i && maxy==i) || (maxx==i && miny==i) || (maxx==i && maxy==i)) { ans += "1"; if (xt.find(x) != xt.end()) xt[x]++; else xt[x] = 1; if (yt.find(y) != yt.end()) yt[y]++; else yt[y] = 1; } else if ((!(minx==i || maxx==i) && ys[y].size()==1 && xt[x]==1)) { ans += "1"; } else if ((!(miny==i || maxy==i) && xs[x].size()==1 && yt[y]==1)) { ans += "1"; } else ans += "0"; // (!(minx==i || maxx==i) && !(miny==i || maxy==i)) ans += "0"; // else ans += "1"; } //2nd pass -- validating the 0s (no tower) // for (lln i=0;i<n;i++) { // lln x = get<0>(points[i]), y = get<1>(points[i]); // if (ans[i]=='1') continue; // bool surrounded = false; // if (xt[x]==2 || yt[y]==2) surrounded = true; // if (!surrounded) ans[i]='1'; // } // for (const auto& k : ys) { // lln yval = k.first; // vector<lln> row = k.second; // if (row.size()>1 && yt[yval]==1) { // //smth is wrong // } // } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) 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...