답안 #544692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544692 2022-04-02T14:30:22 Z AbdelmagedNour Lightning Rod (NOI18_lightningrod) C++17
100 / 100
1829 ms 242120 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N=10000005;
int n,a[N],b[N],nxta[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;
    }
    stack<int>st;
    for(int i=n-1;i>=0;i--){
        while(!st.empty()&&a[st.top()]<a[i])st.pop();
        nxta[i]=(st.empty()?-1:st.top());
        st.push(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]);
    }
    cout<<res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1303 ms 114736 KB Output is correct
2 Correct 1373 ms 129572 KB Output is correct
3 Correct 1316 ms 117696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 388 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 388 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 39 ms 2948 KB Output is correct
15 Correct 42 ms 3060 KB Output is correct
16 Correct 38 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1396 ms 118464 KB Output is correct
2 Correct 1405 ms 167344 KB Output is correct
3 Correct 1380 ms 159208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1303 ms 114736 KB Output is correct
2 Correct 1373 ms 129572 KB Output is correct
3 Correct 1316 ms 117696 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 0 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 388 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 39 ms 2948 KB Output is correct
18 Correct 42 ms 3060 KB Output is correct
19 Correct 38 ms 2944 KB Output is correct
20 Correct 1396 ms 118464 KB Output is correct
21 Correct 1405 ms 167344 KB Output is correct
22 Correct 1380 ms 159208 KB Output is correct
23 Correct 1732 ms 120388 KB Output is correct
24 Correct 1829 ms 242120 KB Output is correct
25 Correct 1759 ms 226728 KB Output is correct