Submission #1168596

#TimeUsernameProblemLanguageResultExecution timeMemory
1168596zh_hLightning Rod (NOI18_lightningrod)C++20
66 / 100
1102 ms197592 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...