Submission #571107

# Submission time Handle Problem Language Result Execution time Memory
571107 2022-06-01T09:07:49 Z web Building Skyscrapers (CEOI19_skyscrapers) C++17
0 / 100
241 ms 12024 KB
#include <bitset>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
vector<bitset<2*1000000001>> grid;
void setBits(int x,int y)
{
    for(int i = x-1; i<= x+1; ++i)
    {
        for(int j = y-1; j<= y+1; ++j)
        {
            grid[x].set(y);
        }
    }
}


bool isAdjacent(pair<long, pair<long, int>>s1, pair<long, pair<long, int>>s2)
  {  return abs(s1.first -s2.first ) <= 1 && abs(s1.second.first - s2.second.first) <=1;}

bitset<150000> visited;
vector<vector<int>> adjList;
vector<pair<long,pair<long, int>>> buildings;
void DFS(int currNode, int prev)
{
    visited.set(currNode);
    for(auto build : adjList[currNode])
    {
        if(!visited.test(build))
        {
            if(build == prev)
                continue;
            else
                DFS(build, currNode);
        }
    }
}

int main()
{
    int n; cin>>n;
    int t; cin>>t;
    buildings.resize(n);
    for(int i = 0; i<n; ++i)
    {
        long a; long b; cin>>a>>b;
        buildings[i] = {a,{b, i}};
    }
    adjList.resize(n);
    sort(buildings.begin(), buildings.end());
    for(int i = 0; i<n-1; ++i)
    {
        for(int j = i+1; j<n; ++j)
        {
            if(buildings[j].first - buildings[i].first > 1)
                break;
            else
            {
                if(isAdjacent(buildings[i], buildings[j]))
                {
                    adjList[i].push_back(j);
                    adjList[j].push_back(i);
                }
            }
        }
    }
    
    //DFS
    DFS(0, 0);
    for(int i = 0; i<n; ++i)
    {
        if(!visited.test(i))
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(int i = 0; i<n; ++i)
    {
        cout<<buildings[i].second.second+1<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 1 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 1 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 1 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB ans=NO N=1934
2 Correct 2 ms 468 KB ans=NO N=1965
3 Incorrect 8 ms 572 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 1 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 125 ms 10212 KB ans=NO N=66151
2 Correct 58 ms 4652 KB ans=NO N=64333
3 Incorrect 241 ms 12024 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB ans=NO N=1934
2 Correct 2 ms 468 KB ans=NO N=1965
3 Incorrect 8 ms 572 KB Full cells must be connected
4 Halted 0 ms 0 KB -