답안 #654448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654448 2022-10-31T10:37:25 Z ktkerem Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 37356 KB
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll , ll> llll;
#define fi first
#define sec second
#define all(x)  x.begin() , x.end()
#define pb push_back
const ll ous = 2e5+7;
std::vector<llll> ar ;std::vector<ll> adj[ous] , nds(ous , 0) , par(ous) , sz(ous) , ans(ous , 1) , rar(ous) , kr(ous) , ant(ous);
ll n , m , o;
ll fin(ll x){
    if(par[x] == x){
        return x;
    }
    return par[x] = fin(par[x]);
}
void mrg(ll x , ll y){
    x = fin(x);y = fin(y);
    if(sz[y] > sz[x]){
        std::swap(x , y);
    }
    if(x != y){
        par[y] = x;
        sz[x] += sz[y]; 
    }
}
void dfs(ll crt){
    o += rar[crt];
    nds[crt] = 1;
    for(auto j:adj[crt]){
        if(fin(crt) != fin(j) && nds[j] == 0){
            mrg(crt , j);
            dfs(j);
        }
    }
}
void solve(){
    ll n , m;std::cin >> n >> m;
    ar.resize(n);
    for(ll i = 0;n>i;i++){
        std::cin >> ar[i].fi;
        ar[i].sec = i + 1;
        rar[i+1] = ar[i].fi;
    }
    for(ll i = 0;m>i;i++){
        ll x , y;std::cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    std::sort(all(ar) , std::greater<llll>());
    ll ik = 1;
    for(;n > ik;ik++){
        if(ar[ik].fi != ar[ik-1].fi){
            break;
        }
    }
    while(n > ik){
        for(ll i = 0;n>+i;i++){
            par[i] = i;
            sz[i] = 1;
            nds[i] = 0;
            kr[i] = 0;
            ant[i] = 0;
        }
        for(ll i = 0;ik>i;i++){
            nds[ar[i].sec] = 1; 
        }
        for(ll i = ik;n>i;i++){
            ans[ar[i].sec] = 0;
        }
        for(ll i = 1;n>=i;i++){
            if(nds[i] == 0){
                dfs(i);
                kr[fin(i)] = o;
                o = 0;
            }
        }
        for(ll i = 0;ik>i;i++){
            for(auto j:adj[ar[i].sec]){
                ll ff = fin(j);
                if(kr[ff] >= ar[i].fi){
                    ant[ff] |= ans[ar[i].sec];
                }
            }
        }
        for(ll i = 1;n>+i;i++){
            ans[i] |= ant[fin(i)];
        }
        ik++;
        for(;n > ik;ik++){
            if(ar[ik-1].fi != ar[ik].fi){
                break;
            }
        }
    }
    for(ll i = 1;n>=i;i++){
        std::cout << ans[i];
    }
    std::cout <<"\n";

}
signed main(){
    std::ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15956 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Correct 8 ms 15956 KB Output is correct
4 Incorrect 128 ms 16140 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Execution timed out 1097 ms 35084 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Execution timed out 1087 ms 37356 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15956 KB Output is correct
2 Correct 498 ms 26536 KB Output is correct
3 Correct 443 ms 26472 KB Output is correct
4 Correct 483 ms 26544 KB Output is correct
5 Correct 205 ms 26488 KB Output is correct
6 Correct 170 ms 26220 KB Output is correct
7 Incorrect 162 ms 27116 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15956 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Correct 8 ms 15956 KB Output is correct
4 Incorrect 128 ms 16140 KB Output isn't correct
5 Halted 0 ms 0 KB -