Submission #905976

# Submission time Handle Problem Language Result Execution time Memory
905976 2024-01-13T08:18:03 Z AndreyPavlov Lightning Rod (NOI18_lightningrod) C++17
100 / 100
1379 ms 157248 KB
/* Includes */
#include <bits/stdc++.h>
#define se second
#define fi first
/* Using libraries */
using namespace std;

/* Defines */
template <class T>
using vc = vector <T>;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
template <class T>
using pq = priority_queue <T, vector <T>, less <T>>;
template <class T>
using pqr = priority_queue <T, vector <T>, greater <T>>;
#pragma GCC optimize ("03,unroll-loops")

template<class T>
void output(T &a) {
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int inf = 1e18;
const int mod = 1e9 + 7;
const int INF = 1e9;
const int N = 5100;

void solve() {
    int n;
    cin >> n;
    stack <pii> st;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        while (!st.empty() && y - (x - st.top().fi) >= st.top().se) {
            st.pop();
        }
        if (st.empty() || st.top().se - (x - st.top().fi) < y) {
            st.push({x, y});
        }
    }
    cout << st.size() << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    while (t--) {
        solve();
    }
}
/*
1
1 + 2
1 + 2 + 3
 */

Compilation message

lightningrod.cpp:45:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   45 | const int inf = 1e18;
      |                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1194 ms 136336 KB Output is correct
2 Correct 1175 ms 137040 KB Output is correct
3 Correct 1138 ms 132280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 33 ms 2400 KB Output is correct
15 Correct 29 ms 2392 KB Output is correct
16 Correct 27 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1143 ms 99752 KB Output is correct
2 Correct 1172 ms 99888 KB Output is correct
3 Correct 1128 ms 97168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1194 ms 136336 KB Output is correct
2 Correct 1175 ms 137040 KB Output is correct
3 Correct 1138 ms 132280 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 33 ms 2400 KB Output is correct
18 Correct 29 ms 2392 KB Output is correct
19 Correct 27 ms 2660 KB Output is correct
20 Correct 1143 ms 99752 KB Output is correct
21 Correct 1172 ms 99888 KB Output is correct
22 Correct 1128 ms 97168 KB Output is correct
23 Correct 1379 ms 97376 KB Output is correct
24 Correct 1313 ms 157248 KB Output is correct
25 Correct 1292 ms 140332 KB Output is correct