답안 #714641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714641 2023-03-25T07:09:49 Z Khizri Stranded Far From Home (BOI22_island) C++17
20 / 100
1000 ms 352852 KB
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
    if(a>b) swap(a,b);
    if(a==0) return a+b;
    return gcd(b%a,a);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool is_prime(ll n){
    ll k=sqrt(n);

    if(n==2) return true;
    if(n<2||n%2==0||k*k==n) return false;
    for(int i=3;i<=k;i+=2){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
int t=1,n,m,arr[mxn],sub[mxn],sign[mxn],ans[mxn];
vector<int>vt[mxn];
bool f(int a,int b){
    return arr[a]<arr[b];
}
bool check(int u){
    priority_queue<pii,vector<pii>,greater<pii>>q;
    ll ans=arr[u];
    for(int v:vt[u]){
        q.push({arr[v],v});
    }
    vector<int>color(n+5);
    color[u]=1;
    while(q.size()){
        pii p=q.top();
        q.pop();
        int u=p.S;
        ll sum=p.F;
        if(color[u]) continue;
        if(sum>ans) return false;
        ans+=sum;
        color[u]=1;
        for(int v:vt[u]){
            if(!color[v]){
                q.push({arr[v],v});
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(!color[i]) return false;
    }
    return true;
}
void dfs(int u,int p){
    for(int v:vt[u]){
        if(v!=p){
            dfs(v,u);
            sub[u]+=sub[v];
            if(sub[v]>=arr[u]){
                sign[v]=1;
            }
            else{
                sign[v]=0;
            }
        }
    }
    sub[u]+=arr[u];
}
void dfs2(int u,int p){
    ans[u]=1;
    for(int v:vt[u]){
        if(v!=p){
            if(sign[v]){
                dfs2(v,u);
            }
        }
    }
}
void solve2(){
    dfs(1,-1);
    dfs2(1,-1);
    for(int i=1;i<=n;i++){
        cout<<ans[i];
    }
    cout<<endl;
}
void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    while(m--){
        int a,b;
        cin>>a>>b;
        vt[a].pb(b);
        vt[b].pb(a);
    }
    if(n>2000){
        solve2();
        return;
    }
    for(int i=1;i<=n;i++){
        if(check(i)){
            cout<<1;
        }
        else{
            cout<<0;
        }
    }
    cout<<endl;
}
signed main(){
    IOS;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 206 ms 5140 KB Output is correct
5 Correct 161 ms 5120 KB Output is correct
6 Correct 317 ms 5140 KB Output is correct
7 Correct 213 ms 5152 KB Output is correct
8 Correct 166 ms 5076 KB Output is correct
9 Correct 205 ms 5196 KB Output is correct
10 Correct 68 ms 5116 KB Output is correct
11 Correct 64 ms 5112 KB Output is correct
12 Correct 61 ms 5148 KB Output is correct
13 Correct 111 ms 5120 KB Output is correct
14 Correct 92 ms 5140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 161 ms 24940 KB Output is correct
4 Correct 155 ms 26604 KB Output is correct
5 Correct 166 ms 22460 KB Output is correct
6 Correct 218 ms 23004 KB Output is correct
7 Correct 169 ms 23068 KB Output is correct
8 Correct 179 ms 23376 KB Output is correct
9 Correct 134 ms 23444 KB Output is correct
10 Correct 107 ms 21400 KB Output is correct
11 Correct 92 ms 22640 KB Output is correct
12 Correct 154 ms 20452 KB Output is correct
13 Correct 130 ms 34692 KB Output is correct
14 Correct 129 ms 34980 KB Output is correct
15 Correct 154 ms 37840 KB Output is correct
16 Correct 85 ms 36716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 150 ms 33212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1081 ms 352852 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 206 ms 5140 KB Output is correct
5 Correct 161 ms 5120 KB Output is correct
6 Correct 317 ms 5140 KB Output is correct
7 Correct 213 ms 5152 KB Output is correct
8 Correct 166 ms 5076 KB Output is correct
9 Correct 205 ms 5196 KB Output is correct
10 Correct 68 ms 5116 KB Output is correct
11 Correct 64 ms 5112 KB Output is correct
12 Correct 61 ms 5148 KB Output is correct
13 Correct 111 ms 5120 KB Output is correct
14 Correct 92 ms 5140 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 161 ms 24940 KB Output is correct
18 Correct 155 ms 26604 KB Output is correct
19 Correct 166 ms 22460 KB Output is correct
20 Correct 218 ms 23004 KB Output is correct
21 Correct 169 ms 23068 KB Output is correct
22 Correct 179 ms 23376 KB Output is correct
23 Correct 134 ms 23444 KB Output is correct
24 Correct 107 ms 21400 KB Output is correct
25 Correct 92 ms 22640 KB Output is correct
26 Correct 154 ms 20452 KB Output is correct
27 Correct 130 ms 34692 KB Output is correct
28 Correct 129 ms 34980 KB Output is correct
29 Correct 154 ms 37840 KB Output is correct
30 Correct 85 ms 36716 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Incorrect 150 ms 33212 KB Output isn't correct
33 Halted 0 ms 0 KB -