Submission #1168589

#TimeUsernameProblemLanguageResultExecution timeMemory
1168589zh_hJourney (NOI18_journey)C++20
0 / 100
1 ms324 KiB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<pair<int, int>> building; // building[id] = (xi, yi)
    vector<pair<int, int>> building_mapper; // building_mapper => sort

    for (int i = 0; i < n; i ++) {
        int x, y;
        cin >> x >> y;

        building.pb({x, y});
        building_mapper.pb({y, i});
    }

    vector<bool> is_covered(n+1, false);

    sort(building_mapper.begin(), building_mapper.end(), [](pair<int, int> a, pair<int, int> b){
        return a.first > b.first;
    });

    int ans = 0;
    for (int i = 0; i < n; i ++) {
        
        if (is_covered[building_mapper[i].second]) {continue;}

        ans ++;
        pair<int, int> cur_building = building[building_mapper[i].second];

        is_covered[building_mapper[i].second] = true;
        for (int j = building_mapper[i].second-1; j >= 0; j --) { // check the left side of cur_building
            if ( abs(building[j].first - cur_building.first) <= abs(building[j].second - cur_building.second) ) {
                is_covered[j] = true;
            } else {
                break;
            }
        }

        for (int j = building_mapper[i].second+1; j < n; j ++) { // check the right side of cur_building
            if ( abs(building[j].first - cur_building.first) <= abs(building[j].second - cur_building.second) ) {
                is_covered[j] = true;
            } else {
                break;
            }
        }

    }

    cout << ans << endl;
}

// key idea:
// 1. find the tallest building that is not covered yet
// 2. plant a lightning rod there
// 3. check the left and right side of the building
//     => if the building is under cover, mark it under cover and continue check
//     => if meet a building is not under cover, stop (think why !)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...