답안 #572926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572926 2022-06-05T13:50:30 Z Theo830 Stranded Far From Home (BOI22_island) C++17
100 / 100
142 ms 23980 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll sum[2000005];
ll par[2000005];
ll find_par(ll x){
    if(par[x] == x){
        return x;
    }
    return par[x] = find_par(par[x]);
}
void enose(ll a,ll b){
    ll p1 = find_par(a);
    ll p2 = find_par(b);
    if(p1 != p2){
        par[p1] = p2;
        sum[p2] += sum[p1];
        sum[p1] = 0;
    }
}
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    f(i,1,n+1){
        par[i] = i;
    }
    ll s[n];
    vector<ii>exo;
    ll maxxi = 0;
    f(i,0,n){
        cin>>s[i];
        sum[i+1] = s[i];
        maxxi = max(maxxi,s[i]);
        exo.pb(ii(s[i],i+1));
    }
    vector<iii>edges;
    f(i,0,m){
        ll a,b;
        cin>>a>>b;
        if(s[a-1] > s[b-1]){
            swap(a,b);
        }
        edges.pb(iii(s[b-1],ii(a,b)));
    }
    sort(all(edges));
    sort(all(exo));
    ll pos = 0;
    ll posa[n];
    ll maxi[n+5] = {0};
    ll p[n];
    ll Next[n+5];
    bool ok[n] = {0};
    for(auto x:exo){
        while(pos < m && edges[pos].F <= x.F){
            maxi[find_par(edges[pos].S.F)] = edges[pos].F;
            Next[find_par(edges[pos].S.F)] = edges[pos].S.S - 1;
            enose(edges[pos].S.F,edges[pos].S.S);
            pos++;
        }
        posa[x.S - 1] = sum[find_par(x.S)];
        p[x.S - 1] = find_par(x.S);
    }
    reverse(all(exo));
    for(auto x:exo){
        if(x.F != maxxi){
            ok[x.S - 1] = ok[Next[p[x.S - 1]]] && (posa[x.S - 1] >= maxi[p[x.S - 1]]);
        }
        else{
            ok[x.S - 1] = true;
        }
    }
    f(i,0,n){
        cout<<ok[i];
    }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 476 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 118 ms 22512 KB Output is correct
4 Correct 107 ms 23244 KB Output is correct
5 Correct 103 ms 21932 KB Output is correct
6 Correct 105 ms 22476 KB Output is correct
7 Correct 106 ms 22472 KB Output is correct
8 Correct 122 ms 22536 KB Output is correct
9 Correct 119 ms 22556 KB Output is correct
10 Correct 92 ms 22500 KB Output is correct
11 Correct 123 ms 23820 KB Output is correct
12 Correct 107 ms 22540 KB Output is correct
13 Correct 96 ms 23896 KB Output is correct
14 Correct 103 ms 23860 KB Output is correct
15 Correct 98 ms 22544 KB Output is correct
16 Correct 72 ms 22316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 135 ms 22412 KB Output is correct
3 Correct 141 ms 22708 KB Output is correct
4 Correct 130 ms 23832 KB Output is correct
5 Correct 102 ms 23372 KB Output is correct
6 Correct 122 ms 22532 KB Output is correct
7 Correct 110 ms 22604 KB Output is correct
8 Correct 115 ms 22596 KB Output is correct
9 Correct 76 ms 22360 KB Output is correct
10 Correct 132 ms 23852 KB Output is correct
11 Correct 112 ms 22916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 138 ms 22408 KB Output is correct
3 Correct 134 ms 22484 KB Output is correct
4 Correct 141 ms 22496 KB Output is correct
5 Correct 129 ms 22484 KB Output is correct
6 Correct 110 ms 21672 KB Output is correct
7 Correct 102 ms 23540 KB Output is correct
8 Correct 99 ms 23788 KB Output is correct
9 Correct 91 ms 13748 KB Output is correct
10 Correct 107 ms 22588 KB Output is correct
11 Correct 115 ms 22956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 476 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 118 ms 22512 KB Output is correct
18 Correct 107 ms 23244 KB Output is correct
19 Correct 103 ms 21932 KB Output is correct
20 Correct 105 ms 22476 KB Output is correct
21 Correct 106 ms 22472 KB Output is correct
22 Correct 122 ms 22536 KB Output is correct
23 Correct 119 ms 22556 KB Output is correct
24 Correct 92 ms 22500 KB Output is correct
25 Correct 123 ms 23820 KB Output is correct
26 Correct 107 ms 22540 KB Output is correct
27 Correct 96 ms 23896 KB Output is correct
28 Correct 103 ms 23860 KB Output is correct
29 Correct 98 ms 22544 KB Output is correct
30 Correct 72 ms 22316 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 135 ms 22412 KB Output is correct
33 Correct 141 ms 22708 KB Output is correct
34 Correct 130 ms 23832 KB Output is correct
35 Correct 102 ms 23372 KB Output is correct
36 Correct 122 ms 22532 KB Output is correct
37 Correct 110 ms 22604 KB Output is correct
38 Correct 115 ms 22596 KB Output is correct
39 Correct 76 ms 22360 KB Output is correct
40 Correct 132 ms 23852 KB Output is correct
41 Correct 112 ms 22916 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 138 ms 22408 KB Output is correct
44 Correct 134 ms 22484 KB Output is correct
45 Correct 141 ms 22496 KB Output is correct
46 Correct 129 ms 22484 KB Output is correct
47 Correct 110 ms 21672 KB Output is correct
48 Correct 102 ms 23540 KB Output is correct
49 Correct 99 ms 23788 KB Output is correct
50 Correct 91 ms 13748 KB Output is correct
51 Correct 107 ms 22588 KB Output is correct
52 Correct 115 ms 22956 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 2 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 592 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 99 ms 22552 KB Output is correct
68 Correct 105 ms 23276 KB Output is correct
69 Correct 103 ms 22052 KB Output is correct
70 Correct 103 ms 22508 KB Output is correct
71 Correct 102 ms 22572 KB Output is correct
72 Correct 114 ms 22572 KB Output is correct
73 Correct 95 ms 22472 KB Output is correct
74 Correct 93 ms 22572 KB Output is correct
75 Correct 113 ms 23812 KB Output is correct
76 Correct 104 ms 22532 KB Output is correct
77 Correct 94 ms 23852 KB Output is correct
78 Correct 97 ms 23728 KB Output is correct
79 Correct 98 ms 22528 KB Output is correct
80 Correct 75 ms 22400 KB Output is correct
81 Correct 125 ms 22448 KB Output is correct
82 Correct 135 ms 22608 KB Output is correct
83 Correct 120 ms 23980 KB Output is correct
84 Correct 102 ms 23400 KB Output is correct
85 Correct 130 ms 22544 KB Output is correct
86 Correct 115 ms 22564 KB Output is correct
87 Correct 109 ms 22468 KB Output is correct
88 Correct 104 ms 23868 KB Output is correct
89 Correct 113 ms 23000 KB Output is correct
90 Correct 142 ms 22488 KB Output is correct
91 Correct 134 ms 22584 KB Output is correct
92 Correct 140 ms 22536 KB Output is correct
93 Correct 129 ms 22416 KB Output is correct
94 Correct 118 ms 21676 KB Output is correct
95 Correct 104 ms 23620 KB Output is correct
96 Correct 90 ms 23808 KB Output is correct
97 Correct 91 ms 13756 KB Output is correct
98 Correct 107 ms 22472 KB Output is correct
99 Correct 110 ms 22980 KB Output is correct
100 Correct 58 ms 6832 KB Output is correct
101 Correct 135 ms 22536 KB Output is correct
102 Correct 115 ms 19336 KB Output is correct
103 Correct 125 ms 20144 KB Output is correct
104 Correct 131 ms 22188 KB Output is correct