Submission #571108

# Submission time Handle Problem Language Result Execution time Memory
571108 2022-06-01T09:09:28 Z web Building Skyscrapers (CEOI19_skyscrapers) C++17
8 / 100
233 ms 11920 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;
vector<int> order;

void DFS(int currNode, int prev)
{
    order.push_back(currNode);
    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[order[i]].second.second+1<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 1 ms 288 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 304 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 1 ms 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 212 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 212 KB ans=YES N=10
12 Correct 1 ms 308 KB ans=YES N=9
13 Correct 1 ms 212 KB ans=YES N=9
14 Correct 1 ms 304 KB ans=YES N=8
15 Correct 1 ms 212 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 1 ms 288 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 304 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 1 ms 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 212 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 212 KB ans=YES N=10
12 Correct 1 ms 308 KB ans=YES N=9
13 Correct 1 ms 212 KB ans=YES N=9
14 Correct 1 ms 304 KB ans=YES N=8
15 Correct 1 ms 212 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Incorrect 1 ms 212 KB Added cell 17 (1,2) not reachable from infinity
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 1 ms 288 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 304 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 1 ms 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 212 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 212 KB ans=YES N=10
12 Correct 1 ms 308 KB ans=YES N=9
13 Correct 1 ms 212 KB ans=YES N=9
14 Correct 1 ms 304 KB ans=YES N=8
15 Correct 1 ms 212 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Incorrect 1 ms 212 KB Added cell 17 (1,2) not reachable from infinity
18 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 340 KB ans=NO N=1965
3 Incorrect 4 ms 596 KB Contestant's solution is not lexicographically largest at index 1824 (1813 vs 622)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 1 ms 288 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 304 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 1 ms 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 212 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 212 KB ans=YES N=10
12 Correct 1 ms 308 KB ans=YES N=9
13 Correct 1 ms 212 KB ans=YES N=9
14 Correct 1 ms 304 KB ans=YES N=8
15 Correct 1 ms 212 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Incorrect 1 ms 212 KB Added cell 17 (1,2) not reachable from infinity
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 128 ms 10340 KB ans=NO N=66151
2 Correct 71 ms 4112 KB ans=NO N=64333
3 Incorrect 233 ms 11920 KB Added cell 69151 (160,-91) not reachable from infinity
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 340 KB ans=NO N=1965
3 Incorrect 4 ms 596 KB Contestant's solution is not lexicographically largest at index 1824 (1813 vs 622)
4 Halted 0 ms 0 KB -