Submission #1101838

# Submission time Handle Problem Language Result Execution time Memory
1101838 2024-10-17T02:33:00 Z blackslex Global Warming (NOI13_gw) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

int gw (int N, int *H) {
    int n = N;
    vector<int> h(n), par(n); iota(par.begin(), par.end(), 0);
    vector<bool> ck(n);
    for (int i = 0; i < n; i++) h[i] = H[i];
    int cnt = 0, ans = 0;
    function<int(int)> fset = [&] (int x) {return (par[x] == x ? x : par[x] = fset(par[x]));};
    auto mg = [&] (int x, int y) {
        if ((x = fset(x)) == (y = fset(y))) return;
        if (ck[x] || ck[y]) par[y] = x, ck[x] = ck[y] = 1;
        else {
            cnt++;
            par[y] = x; ck[x] = ck[y] = 1;
        }
    };
    vector<int> c = h;
    sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin());
    vector<vector<int>> add(n, vector<int>());
    auto get = [&] (int x) {
        return lower_bound(c.begin(), c.end(), x) - c.begin();
    };
    for (int i = 0; i < n; i++) add[get(h[i])].emplace_back(i);
    for (int i = n - 1; i >= 0; i--) {
        for (auto &e: add[i]) {
            if (e && h[e - 1] >= h[e]) mg(e - 1, e);
            if (e != n - 1 && h[e + 1] >= h[e]) mg(e, e + 1);
        }
        ans = max(ans, cnt);
    }
    return ans;
}

Compilation message

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status