Submission #564639

#TimeUsernameProblemLanguageResultExecution timeMemory
564639MajidBuilding Skyscrapers (CEOI19_skyscrapers)C++17
54 / 100
467 ms60068 KiB
#include<bits/stdc++.h> using namespace std; //Types using ll = long long; using db = double; //Vectors #define pb push_back #define sz(vec) ((ll)vec.size()) #define all(vec) vec.begin(), vec.end() //things #define f first #define s second const int SMALLINF = 1e9 + 7; const ll BIGINF = ((ll)1e18) + 7; #define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL); ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; // struct info{ // // ll x, y, pos; // }; void solve(){ ll n, t; cin>>n>>t; vector<pair<ll, ll> > vec(n); map<pair<ll, ll>, bool> visited, exist; map<pair<ll, ll>, ll> order; for(ll i = 0; i < n; i++){ cin>>vec[i].f>>vec[i].s; pair<ll, ll> p; p.f = vec[i].f; p.s = vec[i].s; exist[p] = true; order[p] = i+1; } sort(all(vec)); visited[vec[0]] = true; priority_queue<pair<pair<ll, ll>, ll>, vector<pair<pair<ll, ll>, ll> >, greater<pair<pair<ll, ll>, ll> > > pq; pq.push({vec[0], order[vec[0]]}); vector<ll> res; while(sz(pq)){ ll x = pq.top().f.f, y = pq.top().f.s, pos = pq.top().s; pq.pop(); for(ll i = 0; i < 8; i++){ pair<ll, ll> pch; pch.f = x+dx[i], pch.s = y+dy[i]; if(exist[pch] and !visited[pch]){ visited[pch] = true; pair<pair<ll, ll>, ll> qq; qq.f.f = pch.f; qq.f.s = pch.s; qq.s = order[pch]; pq.push(qq); } } res.pb(pos); } if(sz(res)==n){ cout<<"YES\n"; for(ll i = 0; i < sz(res); i++){ cout<<res[i]<<" "; } } else cout<<"NO\n"; } int main(){ Speeed ll t=1; // cin>>t; while(t--){ solve(); } }
#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...