답안 #870100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870100 2023-11-07T00:05:32 Z Ahmed_Solyman Stranded Far From Home (BOI22_island) C++14
10 / 100
694 ms 524288 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
const int N=2e5+5;
int ans[N],arr[N],n,m;
vector<int>adj[N];
struct DSU{
    vector<ll>P,sz,sum;
    vector<vector<int>>ok;
    void init(int n){
        P.resize(n+5);
        ok.resize(n+5);
        sum.resize(n+5);
        for(int i=0;i<n+5;i++)sum[i]=arr[i],P[i]=i,ok[i].push_back(i);
    }
    int find(int node){
        if(P[node]==node)return node;
        return P[node]=find(P[node]);
    }
    bool unite(int a,int b){
        int p1=find(a);
        int p2=find(b);
        if(p1==p2){
            return 0;
        }
        if(sum[p2]<arr[a]){
            for(auto i:ok[p2])ans[i]=0;
            ok[p2].clear();
        }
        for(auto i:ok[p2])ok[p1].push_back(i);
        ok[p2].clear();
        P[p2]=p1;
        sum[p1]+=sum[p2];
        return 1;
    }
}d;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    #endif
    fast
    cin>>n>>m;
    vector<pair<int,int>>v;
    for(int i=1;i<=n;i++){
        cin>>arr[i];ans[i]=1;
        v.push_back({arr[i],i});
    }
    while(m--){
        int u,v;cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    d.init(n);
    sort(all(v));
    for(int i=0;i<n;i++){
        int node=v[i].second,x=v[i].first;
        for(auto ch:adj[node]){
            if(arr[ch]>arr[node] || (arr[ch]==arr[node] && ch>node))continue;
            d.unite(node,ch);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:94:30: warning: unused variable 'x' [-Wunused-variable]
   94 |         int node=v[i].second,x=v[i].first;
      |                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 4 ms 7004 KB Output is correct
5 Correct 3 ms 5700 KB Output is correct
6 Correct 5 ms 8540 KB Output is correct
7 Correct 5 ms 6968 KB Output is correct
8 Correct 4 ms 6744 KB Output is correct
9 Correct 7 ms 10584 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 12 ms 15708 KB Output is correct
14 Correct 3 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Runtime error 637 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 189 ms 40516 KB Output is correct
3 Correct 171 ms 45764 KB Output is correct
4 Runtime error 694 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Runtime error 676 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 4 ms 7004 KB Output is correct
5 Correct 3 ms 5700 KB Output is correct
6 Correct 5 ms 8540 KB Output is correct
7 Correct 5 ms 6968 KB Output is correct
8 Correct 4 ms 6744 KB Output is correct
9 Correct 7 ms 10584 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 12 ms 15708 KB Output is correct
14 Correct 3 ms 5468 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Runtime error 637 ms 524288 KB Execution killed with signal 9
18 Halted 0 ms 0 KB -