Submission #1060641

#TimeUsernameProblemLanguageResultExecution timeMemory
1060641oviyan_gandhiLightning Rod (NOI18_lightningrod)C++17
100 / 100
532 ms259904 KiB
#include <bits/stdc++.h> using namespace std; inline int readInt() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar_unlocked(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return x; } int X[10000000], Y[10000000]; bool use[10000000]; // whether i contains j bool contains(int i, int j){ return abs(X[i] - X[j]) <= (Y[i] - Y[j]); } int main(){ int N = readInt(); for(int i = 0; i < N; i++) { X[i] = readInt(); Y[i] = readInt(); use[i] = true; } stack<int> s; for (int i = 0; i < N; i++){ while (!s.empty() && !contains(s.top(), i)) s.pop(); if (!s.empty()) use[i] = false; s.push(i); } while (!s.empty()) s.pop(); for (int i = N-1; i >= 0; i--){ while (!s.empty() && !contains(s.top(), i)) s.pop(); if (!s.empty()) use[i] = false; s.push(i); } cout << accumulate(use, use+N, 0) << '\n'; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...