Submission #183945

# Submission time Handle Problem Language Result Execution time Memory
183945 2020-01-10T08:31:22 Z duttaditya18 Lightning Rod (NOI18_lightningrod) C++17
100 / 100
901 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

void fastscan(int &x)
{
    bool neg=false;
    register int c;
    x =0;
    c=getchar_unlocked();
    if(c=='-')
    {
        neg = true;
        c=getchar_unlocked();
    }
    for(;(c>47 && c<58);c=getchar_unlocked())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    fastscan(n);

    // x, y
    int x, y;
    pair<int, int> p[n + 1];

    for(int i = 1; i <= n; i++)
    {
        fastscan(p[i].fi);
        fastscan(p[i].se);
    }

    int suf[n + 2] = {};
    int prf[n + 2] = {};

    prf[0] = INT_MIN;
    prf[n + 1] = INT_MIN;

    suf[0] = INT_MAX;
    suf[n + 1] = INT_MAX;

    for(int i = 1; i <= n; i++)
        prf[i] = max(prf[i - 1], p[i].fi + p[i].se);


    for(int i = n; i >= 1; i--)
        suf[i] = min(suf[i + 1], p[i].fi - p[i].se);


    int ans = n;
    for(int i = 1; i <= n; i++)
        ans -= ((p[i].fi + p[i].se <= prf[i - 1]) || (p[i].fi - p[i].se >= suf[i + 1]));
    cout << ans << endl;
}

Compilation message

lightningrod.cpp: In function 'void fastscan(int&)':
lightningrod.cpp:11:18: warning: ISO C++1z does not allow 'register' storage class specifier [-Wregister]
     register int c;
                  ^
lightningrod.cpp: In function 'int main()':
lightningrod.cpp:34:9: warning: unused variable 'x' [-Wunused-variable]
     int x, y;
         ^
lightningrod.cpp:34:12: warning: unused variable 'y' [-Wunused-variable]
     int x, y;
            ^
# Verdict Execution time Memory Grader output
1 Correct 620 ms 158924 KB Output is correct
2 Correct 622 ms 154892 KB Output is correct
3 Correct 603 ms 148984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 20 ms 6832 KB Output is correct
15 Correct 20 ms 6780 KB Output is correct
16 Correct 19 ms 6008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 603 ms 157644 KB Output is correct
2 Correct 595 ms 157404 KB Output is correct
3 Correct 599 ms 153412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 620 ms 158924 KB Output is correct
2 Correct 622 ms 154892 KB Output is correct
3 Correct 603 ms 148984 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 20 ms 6832 KB Output is correct
18 Correct 20 ms 6780 KB Output is correct
19 Correct 19 ms 6008 KB Output is correct
20 Correct 603 ms 157644 KB Output is correct
21 Correct 595 ms 157404 KB Output is correct
22 Correct 599 ms 153412 KB Output is correct
23 Correct 901 ms 183524 KB Output is correct
24 Correct 860 ms 262144 KB Output is correct
25 Correct 828 ms 262144 KB Output is correct