Submission #328582

# Submission time Handle Problem Language Result Execution time Memory
328582 2020-11-17T07:02:34 Z wind_reaper Lightning Rod (NOI18_lightningrod) C++17
0 / 100
2000 ms 78316 KB
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <stdio.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;
using namespace __gnu_pbds;
using namespace chrono;

#define pb push_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

// const int INF = 1e9;
const ll INF = LLONG_MAX;
const ll mod = 1000000007;

// const ll mod = 998244353;
long long int read_int(){
    char r;
    bool start=false,neg=false;
    long long int ret=0;
    while(true){
        r=getchar();
        if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
            continue;
        }
        if((r-'0'<0 || r-'0'>9) && r!='-' && start){
            break;
        }
        if(start)ret*=10;
        start=true;
        if(r=='-')neg=true;
        else ret+=r-'0';
    }
    if(!neg)
        return ret;
    else
        return -ret;
}
vpi a;
inline bool covers(int i, int j){
    if(abs(a[i].f - a[j].f) <= a[i].s - a[j].s)
        return true;

    return false;
}
void solve(int tc){
    int n;
    cin >> n; 

    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].f = read_int();
        a[i].s = read_int();
    }

    stack<int> r;
    r.push(0); 
    for(int i = 1; i < n; i++){
        if(covers(r.top(), i)) continue;

        while(!r.empty() && covers(i, r.top())) 
            r.pop();

        r.push(i);
    }

    cout << r.size() << '\n';
}


int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    #ifdef LOCAL
        auto begin = high_resolution_clock::now();
    #endif

    int tc = 1;
    // cin >> tc; 
    for (int t = 0; t < tc; t++) solve(t);
    
    #ifdef LOCAL 
        auto end = high_resolution_clock::now();
        cout << fixed << setprecision(4) << "Execution Time: " << duration_cast<duration<double>>(end - begin).count() << "seconds" << endl;
    #endif
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 76268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 78316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 76268 KB Time limit exceeded
2 Halted 0 ms 0 KB -