제출 #447037

#제출 시각아이디문제언어결과실행 시간메모리
447037fhvirusBuilding Skyscrapers (CEOI19_skyscrapers)C++17
8 / 100
309 ms16016 KiB
// Knapsack DP is harder than FFT. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define ff first #define ss second #define pb emplace_back #define AI(x) begin(x),end(x) template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;} template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;} #ifdef OWO #define debug(args...) SDF(#args, args) #define OIU(args...) ostream& operator<<(ostream&O,args) #define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;} LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss) template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));} template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';} #else #pragma GCC optimize("Ofast") #define debug(...) ((void)0) #endif // consider doing reverse // pluck the biggest and reachable out // then update the neighbor to touched and reachable // priority queue maintain valid points // reach: can be reached from outside // touch: has a neighbor plucked struct DSU { int n, s; vector<int> f; DSU(int n = 0) : n(n), s(n), f(n+1) { iota(AI(f), 0); } int F(int a){ return a == f[a] ? a : f[a] = F(f[a]); } int M(int a, int b){ a = F(a), b = F(b); if(a == b) return false; f[b] = a; --s; return true; } int operator() (int a){ return F(a); } }; struct LISAN : vector<int> { void done() { sort(AI()); erase(unique(AI()), end()); } int operator() (int a) { return lower_bound(AI(), a) - begin(); } }; const int kN = 150051; const int INF = 1e9 + 7; const array<pii, 4> d4 = {pii(1, 0), pii(-1, 0), pii(0, 1), pii(0, -1)}; const array<pii, 8> d8 = {pii(1, 1), pii(1, 0), pii(1,-1), pii(0, 1), pii(0, -1), pii(-1, 1), pii(-1, 0), pii(-1, -1)}; int n, t; pii a[kN]; map<pii, int> mp; vector<int> adj[kN], bdj[kN]; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> t; DSU dsu(n); for(int r, c, i = 1; i <= n; ++i){ cin >> r >> c; a[i] = pii(r, c); mp[pii(r, c)] = i; } for(int i = 1; i <= n; ++i){ auto [r, c] = a[i]; for(auto [dr, dc]: d8){ pii u(r + dr, c + dc); if(mp.count(u)){ int v = mp[u]; if(dsu.M(i, v)){ adj[i].pb(v); adj[v].pb(i); } } } } for(int i = 1; i <= n; ++i) debug(i, adj[i]); if(dsu.s != 1){ cout << "NO"; return 0; } cout << "YES\n"; vector<int> vis(n+1, 0); queue<int> q; q.push(1); vis[1] = 1; while(!q.empty()){ int u = q.front(); q.pop(); cout << u << ' '; for(int v: adj[u]) if(!vis[v]) q.push(v), vis[v] = 1; } 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...