답안 #968692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968692 2024-04-23T20:38:26 Z vladilius Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 39464 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct dsu{
    vector<int> p, sz;
    vector<bool> out;
    vector<vector<int>> all;
    vector<ll> s;
    set<pii> st;
    int n;
    dsu(int ns, vector<int>& x){
        n = ns;
        p.resize(n + 1);
        sz.resize(n + 1);
        s.resize(n + 1);
        out.assign(n + 1, 1);
        all.resize(n + 1);
        for (int i = 1; i <= n; i++){
            p[i] = i;
            sz[i] = 1;
            s[i] = x[i];
            all[i] = {i};
            st.insert({s[i], i});
        }
    }
    int get(int v){
        if (p[v] != v){
            p[v] = get(p[v]);
        }
        return p[v];
    }
    void unite(int x, int y){
        x = get(x); y = get(y);
        if (x == y) return;
        if (sz[x] > sz[y]){
            swap(x, y);
        }
        st.erase({s[y], y});
        st.erase({s[x], x});
        p[x] = y;
        sz[y] += sz[x];
        for (int i: all[x]) all[y].push_back(i);
        s[y] += s[x];
        st.insert({s[y], y});
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m; cin>>n>>m;
    vector<int> x(n + 1), p = {0};
    for (int i = 1; i <= n; i++){
        cin>>x[i];
        p.push_back(i);
    }
    auto cmp = [&](int i, int j){
        return x[i] < x[j];
    };
    sort(p.begin(), p.end(), cmp);
    
    vector<int> g[n + 1];
    while (m--){
        int a, b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    int i = 1;
    dsu T(n, x);
    while (i <= n){
        int j = i;
        while (j <= n && x[p[i]] == x[p[j]]){
            j++;
        }
        for (int k = i; k < j; k++){
            int v = p[k];
            for (int u: g[v]){
                if (x[u] <= x[v]){
                    T.unite(u, v);
                }
            }
        }
        if (j > n) break;
        int nxt = x[p[j]];
       
        auto it = T.st.begin();
        while (it != T.st.end() && (*it).first < nxt){
            auto [s, v] = *it;
            for (int i: T.all[v]){
                T.out[i] = 0;
            }
            it++;
        }
        
        i = j;
    }
    
    for (int i = 1; i <= n; i++){
        cout<<T.out[i];
    }
    cout<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 4 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Execution timed out 1064 ms 37016 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1075 ms 36264 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 463 ms 39464 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 4 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -