답안 #1110479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110479 2024-11-09T14:18:43 Z _callmelucian Stranded Far From Home (BOI22_island) C++14
100 / 100
769 ms 61464 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 2e5 + 5;
int cost[mn], recur[mn], dp[mn];
vector<int> adj[mn], pos[mn];

struct customComp {
    bool operator() (int a, int b) const {
        return cost[a] < cost[b];
    }
};

struct DSU {
    vector<ll> lab, weight;
    vector<set<int, customComp>> adjSet;

    DSU (int sz) : lab(sz + 1), weight(sz + 1, 0), adjSet(sz + 1) {
        for (int i = 1; i <= sz; i++)
            adjSet[i] = set<int, customComp>(all(adj[i])), weight[i] = cost[i];
        return;
    }

    int get (int u) {
        if (!lab[u]) return u;
        return lab[u] = get(lab[u]);
    }

    void unite (int a, int b) {
        a = get(a), b = get(b);
        if (a == b) return;
        if (adjSet[a].size() < adjSet[b].size()) swap(a, b);
        for (int u : adjSet[b]) adjSet[a].insert(u);
        lab[b] = a, weight[a] += weight[b];
        adjSet[b].clear();
    }

    int getRecur (int u) {
        int root = get(u);
        auto it = adjSet[root].upper_bound(u);
        if (it == adjSet[root].end()) return INT_MAX;
        return (weight[root] >= weight[*it] ? *it : 0);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m; cin >> n >> m;
    vector<int> cmp;
    for (int i = 1; i <= n; i++) {
        cin >> cost[i];
        cmp.push_back(cost[i]);
    }
    sort(all(cmp)), filter(cmp);

    for (int i = 1; i <= n; i++) {
        int idx = lower_bound(all(cmp), cost[i]) - cmp.begin();
        pos[idx].push_back(i);
    }

    while (m--) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    DSU dsu(n);
    for (int iter = 0; iter < cmp.size(); iter++) {
        for (int i : pos[iter]) {
            for (int j : adj[i])
                if (cost[j] <= cost[i]) dsu.unite(i, j);
        }
        for (int i : pos[iter]) recur[i] = dsu.getRecur(i);
    }

    for (int iter = cmp.size() - 1; iter >= 0; iter--) {
        for (int i : pos[iter]) {
            if (recur[i] == INT_MAX) dp[i] = 1;
            else if (recur[i]) dp[i] = dp[recur[i]];
        }
    }
    for (int i = 1; i <= n; i++) cout << dp[i];

    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:80:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int iter = 0; iter < cmp.size(); iter++) {
      |                        ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10832 KB Output is correct
2 Correct 2 ms 10832 KB Output is correct
3 Correct 2 ms 10832 KB Output is correct
4 Correct 5 ms 11332 KB Output is correct
5 Correct 5 ms 11344 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 7 ms 11088 KB Output is correct
8 Correct 4 ms 11256 KB Output is correct
9 Correct 3 ms 11240 KB Output is correct
10 Correct 5 ms 11344 KB Output is correct
11 Correct 5 ms 11352 KB Output is correct
12 Correct 5 ms 11344 KB Output is correct
13 Correct 3 ms 11088 KB Output is correct
14 Correct 4 ms 11088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 2 ms 10832 KB Output is correct
3 Correct 211 ms 61464 KB Output is correct
4 Correct 100 ms 45232 KB Output is correct
5 Correct 339 ms 59596 KB Output is correct
6 Correct 329 ms 59840 KB Output is correct
7 Correct 420 ms 61248 KB Output is correct
8 Correct 174 ms 46404 KB Output is correct
9 Correct 322 ms 58700 KB Output is correct
10 Correct 260 ms 57732 KB Output is correct
11 Correct 140 ms 46292 KB Output is correct
12 Correct 199 ms 46276 KB Output is correct
13 Correct 144 ms 44872 KB Output is correct
14 Correct 125 ms 45104 KB Output is correct
15 Correct 266 ms 61452 KB Output is correct
16 Correct 283 ms 60076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10896 KB Output is correct
2 Correct 595 ms 60972 KB Output is correct
3 Correct 514 ms 59996 KB Output is correct
4 Correct 118 ms 46412 KB Output is correct
5 Correct 111 ms 44908 KB Output is correct
6 Correct 492 ms 61420 KB Output is correct
7 Correct 257 ms 61380 KB Output is correct
8 Correct 261 ms 61376 KB Output is correct
9 Correct 215 ms 60100 KB Output is correct
10 Correct 182 ms 53188 KB Output is correct
11 Correct 172 ms 53160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10832 KB Output is correct
2 Correct 227 ms 54592 KB Output is correct
3 Correct 235 ms 54592 KB Output is correct
4 Correct 242 ms 54772 KB Output is correct
5 Correct 142 ms 46412 KB Output is correct
6 Correct 141 ms 44948 KB Output is correct
7 Correct 129 ms 47136 KB Output is correct
8 Correct 97 ms 49932 KB Output is correct
9 Correct 117 ms 37064 KB Output is correct
10 Correct 148 ms 44924 KB Output is correct
11 Correct 164 ms 52928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10832 KB Output is correct
2 Correct 2 ms 10832 KB Output is correct
3 Correct 2 ms 10832 KB Output is correct
4 Correct 5 ms 11332 KB Output is correct
5 Correct 5 ms 11344 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 7 ms 11088 KB Output is correct
8 Correct 4 ms 11256 KB Output is correct
9 Correct 3 ms 11240 KB Output is correct
10 Correct 5 ms 11344 KB Output is correct
11 Correct 5 ms 11352 KB Output is correct
12 Correct 5 ms 11344 KB Output is correct
13 Correct 3 ms 11088 KB Output is correct
14 Correct 4 ms 11088 KB Output is correct
15 Correct 3 ms 10832 KB Output is correct
16 Correct 2 ms 10832 KB Output is correct
17 Correct 211 ms 61464 KB Output is correct
18 Correct 100 ms 45232 KB Output is correct
19 Correct 339 ms 59596 KB Output is correct
20 Correct 329 ms 59840 KB Output is correct
21 Correct 420 ms 61248 KB Output is correct
22 Correct 174 ms 46404 KB Output is correct
23 Correct 322 ms 58700 KB Output is correct
24 Correct 260 ms 57732 KB Output is correct
25 Correct 140 ms 46292 KB Output is correct
26 Correct 199 ms 46276 KB Output is correct
27 Correct 144 ms 44872 KB Output is correct
28 Correct 125 ms 45104 KB Output is correct
29 Correct 266 ms 61452 KB Output is correct
30 Correct 283 ms 60076 KB Output is correct
31 Correct 3 ms 10896 KB Output is correct
32 Correct 595 ms 60972 KB Output is correct
33 Correct 514 ms 59996 KB Output is correct
34 Correct 118 ms 46412 KB Output is correct
35 Correct 111 ms 44908 KB Output is correct
36 Correct 492 ms 61420 KB Output is correct
37 Correct 257 ms 61380 KB Output is correct
38 Correct 261 ms 61376 KB Output is correct
39 Correct 215 ms 60100 KB Output is correct
40 Correct 182 ms 53188 KB Output is correct
41 Correct 172 ms 53160 KB Output is correct
42 Correct 2 ms 10832 KB Output is correct
43 Correct 227 ms 54592 KB Output is correct
44 Correct 235 ms 54592 KB Output is correct
45 Correct 242 ms 54772 KB Output is correct
46 Correct 142 ms 46412 KB Output is correct
47 Correct 141 ms 44948 KB Output is correct
48 Correct 129 ms 47136 KB Output is correct
49 Correct 97 ms 49932 KB Output is correct
50 Correct 117 ms 37064 KB Output is correct
51 Correct 148 ms 44924 KB Output is correct
52 Correct 164 ms 52928 KB Output is correct
53 Correct 3 ms 10832 KB Output is correct
54 Correct 3 ms 10832 KB Output is correct
55 Correct 3 ms 10832 KB Output is correct
56 Correct 5 ms 11344 KB Output is correct
57 Correct 5 ms 11344 KB Output is correct
58 Correct 5 ms 11088 KB Output is correct
59 Correct 5 ms 11160 KB Output is correct
60 Correct 4 ms 11088 KB Output is correct
61 Correct 4 ms 11104 KB Output is correct
62 Correct 5 ms 11512 KB Output is correct
63 Correct 5 ms 11512 KB Output is correct
64 Correct 5 ms 11344 KB Output is correct
65 Correct 4 ms 11088 KB Output is correct
66 Correct 4 ms 11088 KB Output is correct
67 Correct 217 ms 61448 KB Output is correct
68 Correct 116 ms 45000 KB Output is correct
69 Correct 361 ms 59588 KB Output is correct
70 Correct 332 ms 59844 KB Output is correct
71 Correct 386 ms 61380 KB Output is correct
72 Correct 147 ms 46408 KB Output is correct
73 Correct 267 ms 58868 KB Output is correct
74 Correct 210 ms 57620 KB Output is correct
75 Correct 138 ms 46300 KB Output is correct
76 Correct 183 ms 46092 KB Output is correct
77 Correct 141 ms 44968 KB Output is correct
78 Correct 119 ms 44996 KB Output is correct
79 Correct 270 ms 61440 KB Output is correct
80 Correct 223 ms 60100 KB Output is correct
81 Correct 769 ms 60968 KB Output is correct
82 Correct 692 ms 59988 KB Output is correct
83 Correct 106 ms 46596 KB Output is correct
84 Correct 100 ms 44868 KB Output is correct
85 Correct 533 ms 61380 KB Output is correct
86 Correct 277 ms 61380 KB Output is correct
87 Correct 267 ms 61380 KB Output is correct
88 Correct 190 ms 53188 KB Output is correct
89 Correct 163 ms 52932 KB Output is correct
90 Correct 261 ms 54648 KB Output is correct
91 Correct 273 ms 54548 KB Output is correct
92 Correct 263 ms 54796 KB Output is correct
93 Correct 159 ms 46408 KB Output is correct
94 Correct 180 ms 44872 KB Output is correct
95 Correct 145 ms 47248 KB Output is correct
96 Correct 98 ms 49932 KB Output is correct
97 Correct 154 ms 37120 KB Output is correct
98 Correct 201 ms 44868 KB Output is correct
99 Correct 198 ms 52932 KB Output is correct
100 Correct 148 ms 33352 KB Output is correct
101 Correct 582 ms 60052 KB Output is correct
102 Correct 124 ms 39212 KB Output is correct
103 Correct 454 ms 55492 KB Output is correct
104 Correct 543 ms 60868 KB Output is correct