답안 #637788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637788 2022-09-03T09:20:34 Z LeonaRaging Stranded Far From Home (BOI22_island) C++14
100 / 100
298 ms 52172 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "

const ll mod = 1e9 + 7;
const int maxn = 2e5 + 4;
const int INF = 1e9;

int n, m, a[maxn], vis[maxn];
vector<int> adj[maxn], nodes[maxn], vals, myVec[maxn];

struct DisjointSet {
    vector<int> par, Rank;
    DisjointSet(int n) {
        par.resize(n + 4); Rank.resize(n + 4);
        for (int i = 1; i <= n; i++)
            par[i] = i, Rank[i] = vals[a[i]], myVec[i].pb(i);
    }
    int find(int x) {
        if (x != par[x]) par[x] = find(par[x]);
        return par[x];
    }
    bool join(int u, int v) {
        u = find(u); v = find(v);
        if (u == v) return u;
        if (Rank[u] < Rank[v])
            swap(u, v);
        Rank[u] += Rank[v];
        par[v] = u;
        if (myVec[u].size() < myVec[v].size())
            swap(myVec[u], myVec[v]);
        for (auto it : myVec[v]) {
            vis[it] = 1;
            myVec[u].pb(it);
        }
        myVec[v].clear();
        return 1;
    }
};

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        vals.pb(a[i]);
    }
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 1; i <= n; i++) {
        a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
        nodes[a[i]].pb(i);
    }
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        if (a[u] == a[v]) {
            adj[u].pb(v);
            adj[v].pb(u);
        }
        else {
            if (a[u] < a[v]) swap(u, v);
            adj[u].pb(v);
        }
    }
    bitset<maxn> res;
    res.set();
    DisjointSet Dsu(n);
    for (int i = 0; i < (vals.size()); i++) {
        for (int u : nodes[i]) {
            vis[u] = 1;
            for (int v : adj[u]) {
                if (vis[v]) {
                    v = Dsu.find(v);
                    if (Dsu.Rank[v] < vals[a[u]]) {
                        for (int node : myVec[v]) {
                            res[node] = 0;
                        }
                        myVec[v].clear();
                    }
                }
                Dsu.join(u, v);
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << res[i];
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:78:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 0; i < (vals.size()); i++) {
      |                     ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14392 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14676 KB Output is correct
5 Correct 8 ms 14712 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 8 ms 14676 KB Output is correct
8 Correct 9 ms 14580 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 10 ms 14764 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 10 ms 14804 KB Output is correct
13 Correct 8 ms 14616 KB Output is correct
14 Correct 8 ms 14708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14436 KB Output is correct
3 Correct 151 ms 42532 KB Output is correct
4 Correct 149 ms 42840 KB Output is correct
5 Correct 169 ms 48996 KB Output is correct
6 Correct 182 ms 49328 KB Output is correct
7 Correct 177 ms 50264 KB Output is correct
8 Correct 201 ms 44736 KB Output is correct
9 Correct 140 ms 50688 KB Output is correct
10 Correct 157 ms 39024 KB Output is correct
11 Correct 167 ms 44336 KB Output is correct
12 Correct 200 ms 42668 KB Output is correct
13 Correct 151 ms 41772 KB Output is correct
14 Correct 151 ms 42004 KB Output is correct
15 Correct 143 ms 47964 KB Output is correct
16 Correct 108 ms 47116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14440 KB Output is correct
2 Correct 298 ms 47252 KB Output is correct
3 Correct 277 ms 50820 KB Output is correct
4 Correct 158 ms 43432 KB Output is correct
5 Correct 164 ms 41920 KB Output is correct
6 Correct 276 ms 51524 KB Output is correct
7 Correct 173 ms 47972 KB Output is correct
8 Correct 166 ms 47956 KB Output is correct
9 Correct 109 ms 46968 KB Output is correct
10 Correct 134 ms 41304 KB Output is correct
11 Correct 163 ms 41828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 213 ms 39028 KB Output is correct
3 Correct 207 ms 44132 KB Output is correct
4 Correct 241 ms 46104 KB Output is correct
5 Correct 235 ms 50884 KB Output is correct
6 Correct 219 ms 46816 KB Output is correct
7 Correct 179 ms 45428 KB Output is correct
8 Correct 97 ms 42412 KB Output is correct
9 Correct 110 ms 30660 KB Output is correct
10 Correct 265 ms 52116 KB Output is correct
11 Correct 161 ms 41640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14392 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14676 KB Output is correct
5 Correct 8 ms 14712 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 8 ms 14676 KB Output is correct
8 Correct 9 ms 14580 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 10 ms 14764 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 10 ms 14804 KB Output is correct
13 Correct 8 ms 14616 KB Output is correct
14 Correct 8 ms 14708 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14436 KB Output is correct
17 Correct 151 ms 42532 KB Output is correct
18 Correct 149 ms 42840 KB Output is correct
19 Correct 169 ms 48996 KB Output is correct
20 Correct 182 ms 49328 KB Output is correct
21 Correct 177 ms 50264 KB Output is correct
22 Correct 201 ms 44736 KB Output is correct
23 Correct 140 ms 50688 KB Output is correct
24 Correct 157 ms 39024 KB Output is correct
25 Correct 167 ms 44336 KB Output is correct
26 Correct 200 ms 42668 KB Output is correct
27 Correct 151 ms 41772 KB Output is correct
28 Correct 151 ms 42004 KB Output is correct
29 Correct 143 ms 47964 KB Output is correct
30 Correct 108 ms 47116 KB Output is correct
31 Correct 7 ms 14440 KB Output is correct
32 Correct 298 ms 47252 KB Output is correct
33 Correct 277 ms 50820 KB Output is correct
34 Correct 158 ms 43432 KB Output is correct
35 Correct 164 ms 41920 KB Output is correct
36 Correct 276 ms 51524 KB Output is correct
37 Correct 173 ms 47972 KB Output is correct
38 Correct 166 ms 47956 KB Output is correct
39 Correct 109 ms 46968 KB Output is correct
40 Correct 134 ms 41304 KB Output is correct
41 Correct 163 ms 41828 KB Output is correct
42 Correct 8 ms 14420 KB Output is correct
43 Correct 213 ms 39028 KB Output is correct
44 Correct 207 ms 44132 KB Output is correct
45 Correct 241 ms 46104 KB Output is correct
46 Correct 235 ms 50884 KB Output is correct
47 Correct 219 ms 46816 KB Output is correct
48 Correct 179 ms 45428 KB Output is correct
49 Correct 97 ms 42412 KB Output is correct
50 Correct 110 ms 30660 KB Output is correct
51 Correct 265 ms 52116 KB Output is correct
52 Correct 161 ms 41640 KB Output is correct
53 Correct 7 ms 14420 KB Output is correct
54 Correct 7 ms 14436 KB Output is correct
55 Correct 7 ms 14420 KB Output is correct
56 Correct 8 ms 14676 KB Output is correct
57 Correct 8 ms 14748 KB Output is correct
58 Correct 8 ms 14676 KB Output is correct
59 Correct 9 ms 14688 KB Output is correct
60 Correct 8 ms 14576 KB Output is correct
61 Correct 8 ms 14708 KB Output is correct
62 Correct 9 ms 14676 KB Output is correct
63 Correct 10 ms 14712 KB Output is correct
64 Correct 9 ms 14676 KB Output is correct
65 Correct 8 ms 14676 KB Output is correct
66 Correct 8 ms 14676 KB Output is correct
67 Correct 154 ms 47012 KB Output is correct
68 Correct 162 ms 42816 KB Output is correct
69 Correct 170 ms 48956 KB Output is correct
70 Correct 177 ms 49280 KB Output is correct
71 Correct 195 ms 50240 KB Output is correct
72 Correct 199 ms 44784 KB Output is correct
73 Correct 158 ms 50792 KB Output is correct
74 Correct 147 ms 39204 KB Output is correct
75 Correct 150 ms 44372 KB Output is correct
76 Correct 216 ms 42508 KB Output is correct
77 Correct 148 ms 41728 KB Output is correct
78 Correct 143 ms 41876 KB Output is correct
79 Correct 145 ms 48064 KB Output is correct
80 Correct 110 ms 47068 KB Output is correct
81 Correct 272 ms 51580 KB Output is correct
82 Correct 273 ms 51056 KB Output is correct
83 Correct 167 ms 43416 KB Output is correct
84 Correct 142 ms 41752 KB Output is correct
85 Correct 283 ms 51624 KB Output is correct
86 Correct 170 ms 48088 KB Output is correct
87 Correct 186 ms 47952 KB Output is correct
88 Correct 144 ms 41280 KB Output is correct
89 Correct 151 ms 41852 KB Output is correct
90 Correct 237 ms 43592 KB Output is correct
91 Correct 207 ms 44096 KB Output is correct
92 Correct 227 ms 46296 KB Output is correct
93 Correct 241 ms 50956 KB Output is correct
94 Correct 228 ms 46780 KB Output is correct
95 Correct 177 ms 45404 KB Output is correct
96 Correct 98 ms 42412 KB Output is correct
97 Correct 106 ms 30688 KB Output is correct
98 Correct 240 ms 52172 KB Output is correct
99 Correct 152 ms 41720 KB Output is correct
100 Correct 42 ms 19432 KB Output is correct
101 Correct 285 ms 47680 KB Output is correct
102 Correct 211 ms 41768 KB Output is correct
103 Correct 235 ms 40908 KB Output is correct
104 Correct 283 ms 46200 KB Output is correct