답안 #548730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548730 2022-04-14T10:55:56 Z jack715 Lightning Rod (NOI18_lightningrod) C++14
80 / 100
2000 ms 262144 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second

using namespace std;

bool protect(pair<int, int>& a, pair<int, int>& b) {
    return (abs(a.ff-b.ff) <= a.ss-b.ss);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, a, b, ans = 1;
    cin >> n;
    stack<pair<int, int> > select;
    vector<pair<int, int> > nums(n), prot(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i].ff >> nums[i].ss;
        prot[i] = nums[i];
    }
    
    select.push(nums[0]);
    for (int i = 1; i < n; i++) {
        if (!select.empty() && protect(select.top(), nums[i]))
            continue;
        while (!select.empty() && protect(nums[i], select.top())) {
            ans--;
            select.pop();
        }
        ans++;        
        select.push(nums[i]);
    }

    cout << ans << '\n';
    return 0;
}

Compilation message

lightningrod.cpp: In function 'int main()':
lightningrod.cpp:18:12: warning: unused variable 'a' [-Wunused-variable]
   18 |     int n, a, b, ans = 1;
      |            ^
lightningrod.cpp:18:15: warning: unused variable 'b' [-Wunused-variable]
   18 |     int n, a, b, ans = 1;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1559 ms 262144 KB Output is correct
2 Correct 1527 ms 262144 KB Output is correct
3 Correct 1510 ms 262144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 39 ms 6780 KB Output is correct
15 Correct 42 ms 6672 KB Output is correct
16 Correct 36 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1603 ms 248684 KB Output is correct
2 Correct 1571 ms 262144 KB Output is correct
3 Correct 1541 ms 262144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1559 ms 262144 KB Output is correct
2 Correct 1527 ms 262144 KB Output is correct
3 Correct 1510 ms 262144 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 39 ms 6780 KB Output is correct
18 Correct 42 ms 6672 KB Output is correct
19 Correct 36 ms 6604 KB Output is correct
20 Correct 1603 ms 248684 KB Output is correct
21 Correct 1571 ms 262144 KB Output is correct
22 Correct 1541 ms 262144 KB Output is correct
23 Correct 1926 ms 262144 KB Output is correct
24 Execution timed out 2016 ms 262144 KB Time limit exceeded
25 Halted 0 ms 0 KB -