제출 #891443

#제출 시각아이디문제언어결과실행 시간메모리
891443abysmalAdvertisement 2 (JOI23_ho_t2)C++14
100 / 100
454 ms37688 KiB
#include<iostream> #include<stdio.h> #include<stdint.h> #include<vector> #include<algorithm> #include<utility> #include<set> #include<map> #include<queue> #include<stack> #include<iomanip> #include<string> #include<math.h> #include<assert.h> using namespace std; const double PI = (double) atan(1.0) * 4; const int64_t INF = (int64_t) 1e18 + 777; const int64_t mINF = (int64_t) 2e9 + 777; const int64_t offset = (int64_t) 1e6 + 777; const int64_t MOD = 1e9 + 7; const int nbit = 11; const int ndig = 10; const int nchar = 26; const int p1 = 31; const int p2 = 53; const int D = 4; int dr[D] = {0, 1, 0, -1}; int dc[D] = {1, 0, -1, 0}; // 0 right // 1 down // 2 left // 3 up int modadd(int t1, int t2) { int res = t1 + t2; if(res >= MOD) res -= MOD; return res; } int modmul(int t1, int t2) { int64_t res = 1LL * t1 * t2; return (res % MOD); } struct House { int x; int e; House(int x_, int e_) : x(x_), e(e_) {} bool operator < (const House& o) const { if(x == o.x) return e < o.e; return x < o.x; } }; struct Solution { int n; vector<House> a; Solution() {} void solve() { cin >> n; set<pair<int, int> > st; for(int i = 0; i < n; i++) { int x; int e; cin >> x >> e; if(!st.count(make_pair(x, e))) a.emplace_back(x, e); st.insert(make_pair(x, e)); } n = a.size(); sort(a.begin(), a.end()); vector<bool> give(n, true); int max_ = -mINF; for(int i = 0; i < n; i++) { if(a[i].x + a[i].e <= max_) give[i] = false; max_ = max(max_, a[i].x + a[i].e); } max_ = -mINF; for(int i = n - 1; i >= 0; i--) { if(-a[i].x + a[i].e <= max_) give[i] = false; max_ = max(max_, -a[i].x + a[i].e); } int ans = 0; for(int i = 0; i < n; i++) { ans += give[i]; } cout << ans << "\n"; } int modsub(int t1, int t2) { int res = t1 - t2; if(res < 0) res += MOD; return res; } bool BIT(int& mask, int& j) { return (mask & MASK(j)); } int64_t Abs(int64_t t1) { if(t1 < 0) return -t1; return t1; } int MASK(int j) { return (1 << j); } }; void __startup() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); } int main() { __startup(); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { Solution().solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...