답안 #1081883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081883 2024-08-30T12:30:24 Z Tymond Stranded Far From Home (BOI22_island) C++17
100 / 100
190 ms 38448 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct Info{
    vi winners;
    ll s;
    Info(vi xd = {}, ll x = 0LL){
        winners = xd;
        s = x;
    }
};

const int MAXN = 2e5 + 7;
vi g[MAXN];
ll a[MAXN];
Info tab[MAXN];
int rep[MAXN];
int was[MAXN];
int n, m;

int Find(int v){
    if(rep[v] == v){
        return v;
    }
    return rep[v] = Find(rep[v]);
}

void Union(int u, int v, int f){
    if(!f){
        tab[u].winners.clear();
        tab[v].s = (ll)tab[v].s + tab[u].s;

        rep[u] = v;
        return;
    }

    if(sz(tab[u].winners) < sz(tab[v].winners)){
        swap(u, v);
    }

    for(auto ele : tab[v].winners){
        tab[u].winners.pb(ele);
    }
    tab[u].s = (ll)tab[u].s + tab[v].s;
    rep[v] = u;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> m;
    vector<pii> vec;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        vec.pb({(int)a[i], i});
        rep[i] = i;
        was[i] = 0;
        tab[i] = Info({i}, (ll)a[i]);
    }

    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }

    sort(all(vec));
    for(int i = 0; i < n; i++){
        int v = vec[i].se;
       // int c = vec[i].fi;

        was[v] = 1;
        for(auto u : g[v]){
            if(was[u]){
                int r = Find(u);
                int nasz = Find(v);
                if(r == nasz){
                    continue;
                }

                if(tab[r].s >= a[v]){
                    Union(r, nasz, 1);
                }else{
                    Union(r, nasz, 0);
                }
            }
        }
    }

    int r = Find(1);
    vi ans(n + 1, 0);
    for(auto ele : tab[r].winners){
        ans[ele] = 1;
    }

    for(int i = 1; i <= n; i++){
        cout << ans[i];
    }
    cout << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11352 KB Output is correct
2 Correct 6 ms 11356 KB Output is correct
3 Correct 6 ms 11416 KB Output is correct
4 Correct 7 ms 11540 KB Output is correct
5 Correct 7 ms 11612 KB Output is correct
6 Correct 6 ms 11448 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 6 ms 11428 KB Output is correct
9 Correct 7 ms 11612 KB Output is correct
10 Correct 7 ms 11612 KB Output is correct
11 Correct 9 ms 11612 KB Output is correct
12 Correct 6 ms 11608 KB Output is correct
13 Correct 7 ms 11612 KB Output is correct
14 Correct 7 ms 11612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11356 KB Output is correct
2 Correct 6 ms 11356 KB Output is correct
3 Correct 145 ms 34844 KB Output is correct
4 Correct 93 ms 34332 KB Output is correct
5 Correct 103 ms 36288 KB Output is correct
6 Correct 117 ms 37336 KB Output is correct
7 Correct 113 ms 37308 KB Output is correct
8 Correct 100 ms 34952 KB Output is correct
9 Correct 98 ms 38304 KB Output is correct
10 Correct 89 ms 33980 KB Output is correct
11 Correct 122 ms 34648 KB Output is correct
12 Correct 111 ms 33684 KB Output is correct
13 Correct 91 ms 33468 KB Output is correct
14 Correct 88 ms 34236 KB Output is correct
15 Correct 98 ms 35040 KB Output is correct
16 Correct 71 ms 33980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11352 KB Output is correct
2 Correct 134 ms 37824 KB Output is correct
3 Correct 141 ms 38216 KB Output is correct
4 Correct 104 ms 35008 KB Output is correct
5 Correct 118 ms 33984 KB Output is correct
6 Correct 152 ms 37820 KB Output is correct
7 Correct 106 ms 35008 KB Output is correct
8 Correct 107 ms 35004 KB Output is correct
9 Correct 71 ms 33980 KB Output is correct
10 Correct 125 ms 34236 KB Output is correct
11 Correct 109 ms 34064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11356 KB Output is correct
2 Correct 138 ms 35792 KB Output is correct
3 Correct 139 ms 36032 KB Output is correct
4 Correct 148 ms 37444 KB Output is correct
5 Correct 130 ms 38448 KB Output is correct
6 Correct 122 ms 35776 KB Output is correct
7 Correct 97 ms 35724 KB Output is correct
8 Correct 70 ms 34068 KB Output is correct
9 Correct 80 ms 24716 KB Output is correct
10 Correct 150 ms 37732 KB Output is correct
11 Correct 107 ms 33840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11352 KB Output is correct
2 Correct 6 ms 11356 KB Output is correct
3 Correct 6 ms 11416 KB Output is correct
4 Correct 7 ms 11540 KB Output is correct
5 Correct 7 ms 11612 KB Output is correct
6 Correct 6 ms 11448 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 6 ms 11428 KB Output is correct
9 Correct 7 ms 11612 KB Output is correct
10 Correct 7 ms 11612 KB Output is correct
11 Correct 9 ms 11612 KB Output is correct
12 Correct 6 ms 11608 KB Output is correct
13 Correct 7 ms 11612 KB Output is correct
14 Correct 7 ms 11612 KB Output is correct
15 Correct 6 ms 11356 KB Output is correct
16 Correct 6 ms 11356 KB Output is correct
17 Correct 145 ms 34844 KB Output is correct
18 Correct 93 ms 34332 KB Output is correct
19 Correct 103 ms 36288 KB Output is correct
20 Correct 117 ms 37336 KB Output is correct
21 Correct 113 ms 37308 KB Output is correct
22 Correct 100 ms 34952 KB Output is correct
23 Correct 98 ms 38304 KB Output is correct
24 Correct 89 ms 33980 KB Output is correct
25 Correct 122 ms 34648 KB Output is correct
26 Correct 111 ms 33684 KB Output is correct
27 Correct 91 ms 33468 KB Output is correct
28 Correct 88 ms 34236 KB Output is correct
29 Correct 98 ms 35040 KB Output is correct
30 Correct 71 ms 33980 KB Output is correct
31 Correct 7 ms 11352 KB Output is correct
32 Correct 134 ms 37824 KB Output is correct
33 Correct 141 ms 38216 KB Output is correct
34 Correct 104 ms 35008 KB Output is correct
35 Correct 118 ms 33984 KB Output is correct
36 Correct 152 ms 37820 KB Output is correct
37 Correct 106 ms 35008 KB Output is correct
38 Correct 107 ms 35004 KB Output is correct
39 Correct 71 ms 33980 KB Output is correct
40 Correct 125 ms 34236 KB Output is correct
41 Correct 109 ms 34064 KB Output is correct
42 Correct 9 ms 11356 KB Output is correct
43 Correct 138 ms 35792 KB Output is correct
44 Correct 139 ms 36032 KB Output is correct
45 Correct 148 ms 37444 KB Output is correct
46 Correct 130 ms 38448 KB Output is correct
47 Correct 122 ms 35776 KB Output is correct
48 Correct 97 ms 35724 KB Output is correct
49 Correct 70 ms 34068 KB Output is correct
50 Correct 80 ms 24716 KB Output is correct
51 Correct 150 ms 37732 KB Output is correct
52 Correct 107 ms 33840 KB Output is correct
53 Correct 6 ms 11352 KB Output is correct
54 Correct 5 ms 11356 KB Output is correct
55 Correct 5 ms 11356 KB Output is correct
56 Correct 5 ms 11612 KB Output is correct
57 Correct 6 ms 11612 KB Output is correct
58 Correct 6 ms 11548 KB Output is correct
59 Correct 6 ms 11448 KB Output is correct
60 Correct 6 ms 11612 KB Output is correct
61 Correct 5 ms 11612 KB Output is correct
62 Correct 7 ms 11608 KB Output is correct
63 Correct 7 ms 11612 KB Output is correct
64 Correct 6 ms 11620 KB Output is correct
65 Correct 6 ms 11612 KB Output is correct
66 Correct 7 ms 11608 KB Output is correct
67 Correct 94 ms 34752 KB Output is correct
68 Correct 94 ms 34364 KB Output is correct
69 Correct 112 ms 36284 KB Output is correct
70 Correct 108 ms 37308 KB Output is correct
71 Correct 112 ms 37308 KB Output is correct
72 Correct 104 ms 35044 KB Output is correct
73 Correct 108 ms 38336 KB Output is correct
74 Correct 113 ms 33956 KB Output is correct
75 Correct 105 ms 34612 KB Output is correct
76 Correct 102 ms 33680 KB Output is correct
77 Correct 94 ms 33332 KB Output is correct
78 Correct 89 ms 34240 KB Output is correct
79 Correct 94 ms 35008 KB Output is correct
80 Correct 73 ms 34036 KB Output is correct
81 Correct 133 ms 37820 KB Output is correct
82 Correct 132 ms 38072 KB Output is correct
83 Correct 113 ms 35120 KB Output is correct
84 Correct 92 ms 33980 KB Output is correct
85 Correct 140 ms 38036 KB Output is correct
86 Correct 114 ms 35008 KB Output is correct
87 Correct 108 ms 35008 KB Output is correct
88 Correct 95 ms 34292 KB Output is correct
89 Correct 132 ms 33984 KB Output is correct
90 Correct 141 ms 35776 KB Output is correct
91 Correct 141 ms 36028 KB Output is correct
92 Correct 134 ms 37312 KB Output is correct
93 Correct 190 ms 38332 KB Output is correct
94 Correct 118 ms 35884 KB Output is correct
95 Correct 108 ms 35776 KB Output is correct
96 Correct 74 ms 34032 KB Output is correct
97 Correct 73 ms 24804 KB Output is correct
98 Correct 144 ms 37824 KB Output is correct
99 Correct 112 ms 33984 KB Output is correct
100 Correct 30 ms 15704 KB Output is correct
101 Correct 135 ms 36544 KB Output is correct
102 Correct 107 ms 30916 KB Output is correct
103 Correct 122 ms 31724 KB Output is correct
104 Correct 160 ms 35128 KB Output is correct