Submission #544689

# Submission time Handle Problem Language Result Execution time Memory
544689 2022-04-02T14:27:01 Z AbdelmagedNour Lightning Rod (NOI18_lightningrod) C++17
80 / 100
2000 ms 262144 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N=10000005;
int n,a[N],b[N],nxta[N],nxtb[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a[i]=y-x;
        b[i]=y+x;
    }
    vector<int>st;
    for(int i=n-1;i>=0;i--){
        while(!st.empty()&&a[st.back()]<a[i])st.pop_back();
        nxta[i]=(st.empty()?-1:st.back());
        st.push_back(i);
    }
    st.clear();
    for(int i=n-1;i>=0;i--){
        while(!st.empty()&&b[st.back()]<b[i])st.pop_back();
        nxtb[i]=(st.empty()?n:st.back());
        st.push_back(i);
    }
    int res=0,pos=0,mx=INT_MIN;
    while(pos<n){
        if(b[pos]<=mx){
            pos++;
            continue;
        }
        res++;
        while(nxta[pos]!=-1)pos=nxta[pos];
        mx=max(mx,b[pos]);
        pos=nxtb[pos];
    }
    cout<<res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1548 ms 262144 KB Output is correct
2 Correct 1523 ms 262144 KB Output is correct
3 Correct 1469 ms 262144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 48 ms 6804 KB Output is correct
15 Correct 48 ms 6664 KB Output is correct
16 Correct 39 ms 6528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1632 ms 262144 KB Output is correct
2 Correct 1624 ms 262144 KB Output is correct
3 Correct 1657 ms 262144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1548 ms 262144 KB Output is correct
2 Correct 1523 ms 262144 KB Output is correct
3 Correct 1469 ms 262144 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 48 ms 6804 KB Output is correct
18 Correct 48 ms 6664 KB Output is correct
19 Correct 39 ms 6528 KB Output is correct
20 Correct 1632 ms 262144 KB Output is correct
21 Correct 1624 ms 262144 KB Output is correct
22 Correct 1657 ms 262144 KB Output is correct
23 Execution timed out 2009 ms 262144 KB Time limit exceeded
24 Halted 0 ms 0 KB -