Submission #1029453

# Submission time Handle Problem Language Result Execution time Memory
1029453 2024-07-20T22:14:31 Z rsinventor Global Warming (NOI13_gw) C++17
23 / 40
163 ms 21516 KB
#include <bits/stdc++.h>

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

//    freopen("warming.in", "r", stdin);
//    freopen("warming.out", "w", stdout);

    int n;
    cin >> n;
    int h[n];
    vector<pair<int, int>> sh2(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
        sh2[i].first = h[i];
        sh2[i].second = i;
    }
    sort(sh2.begin(), sh2.end());

    int mx_islands = 0;
    int islands = 0;
    for(int i = 0; i < n; i++) {
        if(max(0, h[i])>0 && (i==0 || max(0, h[i-1])==0)) islands++;
    }
    mx_islands = max(mx_islands, islands);
    for(int i = 0; i < sh2.size(); i++) {
        int s = sh2[i].second;
        islands++;
        if(h[s+1]<h[s]) {
            islands--;
        }
        if(h[s-1]<=h[s]) {
            islands--;
        }
        mx_islands = max(mx_islands, islands);
    }

    cout << mx_islands << endl;


    return 0;
}

Compilation message

gw.cpp: In function 'int main()':
gw.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i < sh2.size(); i++) {
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2396 KB Output is correct
2 Correct 15 ms 2260 KB Output is correct
3 Correct 14 ms 2472 KB Output is correct
4 Correct 20 ms 2472 KB Output is correct
5 Correct 13 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 21276 KB Output is correct
2 Correct 153 ms 21332 KB Output is correct
3 Correct 151 ms 21384 KB Output is correct
4 Correct 158 ms 21516 KB Output is correct
5 Correct 163 ms 20820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 20744 KB Output is correct
2 Correct 154 ms 20816 KB Output is correct
3 Correct 148 ms 20816 KB Output is correct
4 Incorrect 135 ms 15032 KB Output isn't correct
5 Halted 0 ms 0 KB -