# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544459 | ac2hu | Lightning Rod (NOI18_lightningrod) | C++14 | 1888 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
void setIO(string name) {
#ifdef DEBUG
#else
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
#endif
}
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n;cin >> n;
vector<pair<int,int>> a(n);
for(auto &e : a){
cin >> e.first >> e.second;
}
auto fit = [&](pair<int,int> a,pair<int,int> b) -> bool{
// if b can't fit a
return (abs(b.first - a.first) <= abs(b.second - a.second));
};
auto better = [&](pair<int,int> a, pair<int,int> b) -> bool{
if(a.first + a.second > b.first + b.second)
return true;
return false;
};
vector<pair<int,int>> st;
st.push_back(a[0]);
for(int i = 1;i<n;i++){
while(st.size() > 0 && fit(a[i], st.back()) && better(a[i], st.back())){
st.pop_back();
}
if(st.size() == 0 || !fit(a[i], st.back())){//(!fit(a[i], st.back()) && !better(st.back(), a[i]))){
st.push_back(a[i]);
}
deb(st);
}
// cout << fit(a[n - 1], st.back()) << " " << better(st.back(), a[n - 1]) << "\n";
cout << st.size() << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |