답안 #654478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654478 2022-10-31T12:52:51 Z prvocislo Stranded Far From Home (BOI22_island) C++17
100 / 100
288 ms 30632 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 2e5 + 5;
struct comp
{
    ll sum = 0;
    priority_queue<pair<int, int> > s;
};
vector<comp> c(maxn);
vector<int> a(maxn), p(maxn);
int root(int u)
{
    return u == p[u] ? u : p[u] = root(p[u]);
}
int merge(int u, int v)
{
    u = root(u), v = root(v);
    if (u == v) return u;
    if (c[u].s.size() < c[v].s.size()) swap(u, v);
    p[v] = u;
    c[u].sum += c[v].sum;
    while (!c[v].s.empty()) c[u].s.push(c[v].s.top()), c[v].s.pop();
    return u;
}
bool cmp(int i, int j)
{
    return a[i] < a[j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > w;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        w.push_back({ a[i], i });
        c[i].sum = a[i];
        p[i] = i;
    }
    vector<vector<int> > g(n);
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        if (make_pair( a[u], u ) > make_pair( a[v], v )) swap(u, v);
        c[u].s.push({-a[v], -v});
        g[v].push_back(u);
    }
    vector<int> de(n, -1);
    sort(w.begin(), w.end());
    for (pair<int, int> p : w)
    {
        int u = p.second, cm = u;
        for (int v : g[u]) cm = merge(cm, v);
        while (!c[cm].s.empty() && -c[cm].s.top().second == u) c[cm].s.pop();
        if (!c[cm].s.empty() && a[-c[cm].s.top().second] <= c[cm].sum) de[u] = -c[cm].s.top().second;
    }
    reverse(w.begin(), w.end());
    vector<bool> ans(n, false);
    for (pair<int, int> p : w)
    {
        int u = p.second;
        if (p == w[0]) ans[u] = true;
        else if (de[u] != -1) ans[u] = ans[de[u]];
    }
    for (int i = 0; i < n; i++) cout << "01"[ans[i]];
    cout << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 7 ms 9772 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 7 ms 9828 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 7 ms 9812 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 7 ms 9900 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9704 KB Output is correct
2 Correct 5 ms 9652 KB Output is correct
3 Correct 170 ms 29620 KB Output is correct
4 Correct 190 ms 29028 KB Output is correct
5 Correct 237 ms 28868 KB Output is correct
6 Correct 192 ms 29380 KB Output is correct
7 Correct 199 ms 29436 KB Output is correct
8 Correct 250 ms 28344 KB Output is correct
9 Correct 198 ms 30532 KB Output is correct
10 Correct 134 ms 27472 KB Output is correct
11 Correct 165 ms 25208 KB Output is correct
12 Correct 195 ms 28280 KB Output is correct
13 Correct 184 ms 30024 KB Output is correct
14 Correct 201 ms 29948 KB Output is correct
15 Correct 185 ms 30544 KB Output is correct
16 Correct 95 ms 29924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 254 ms 27124 KB Output is correct
3 Correct 242 ms 27180 KB Output is correct
4 Correct 205 ms 29508 KB Output is correct
5 Correct 173 ms 29560 KB Output is correct
6 Correct 220 ms 27200 KB Output is correct
7 Correct 214 ms 29548 KB Output is correct
8 Correct 212 ms 29488 KB Output is correct
9 Correct 106 ms 29260 KB Output is correct
10 Correct 199 ms 25668 KB Output is correct
11 Correct 202 ms 27392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 288 ms 26716 KB Output is correct
3 Correct 260 ms 26684 KB Output is correct
4 Correct 230 ms 26684 KB Output is correct
5 Correct 251 ms 26680 KB Output is correct
6 Correct 252 ms 26244 KB Output is correct
7 Correct 169 ms 27464 KB Output is correct
8 Correct 122 ms 28804 KB Output is correct
9 Correct 203 ms 21960 KB Output is correct
10 Correct 222 ms 27352 KB Output is correct
11 Correct 198 ms 28096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 7 ms 9772 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 7 ms 9828 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 7 ms 9812 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 7 ms 9900 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
15 Correct 6 ms 9704 KB Output is correct
16 Correct 5 ms 9652 KB Output is correct
17 Correct 170 ms 29620 KB Output is correct
18 Correct 190 ms 29028 KB Output is correct
19 Correct 237 ms 28868 KB Output is correct
20 Correct 192 ms 29380 KB Output is correct
21 Correct 199 ms 29436 KB Output is correct
22 Correct 250 ms 28344 KB Output is correct
23 Correct 198 ms 30532 KB Output is correct
24 Correct 134 ms 27472 KB Output is correct
25 Correct 165 ms 25208 KB Output is correct
26 Correct 195 ms 28280 KB Output is correct
27 Correct 184 ms 30024 KB Output is correct
28 Correct 201 ms 29948 KB Output is correct
29 Correct 185 ms 30544 KB Output is correct
30 Correct 95 ms 29924 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 254 ms 27124 KB Output is correct
33 Correct 242 ms 27180 KB Output is correct
34 Correct 205 ms 29508 KB Output is correct
35 Correct 173 ms 29560 KB Output is correct
36 Correct 220 ms 27200 KB Output is correct
37 Correct 214 ms 29548 KB Output is correct
38 Correct 212 ms 29488 KB Output is correct
39 Correct 106 ms 29260 KB Output is correct
40 Correct 199 ms 25668 KB Output is correct
41 Correct 202 ms 27392 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 288 ms 26716 KB Output is correct
44 Correct 260 ms 26684 KB Output is correct
45 Correct 230 ms 26684 KB Output is correct
46 Correct 251 ms 26680 KB Output is correct
47 Correct 252 ms 26244 KB Output is correct
48 Correct 169 ms 27464 KB Output is correct
49 Correct 122 ms 28804 KB Output is correct
50 Correct 203 ms 21960 KB Output is correct
51 Correct 222 ms 27352 KB Output is correct
52 Correct 198 ms 28096 KB Output is correct
53 Correct 5 ms 9736 KB Output is correct
54 Correct 5 ms 9704 KB Output is correct
55 Correct 6 ms 9684 KB Output is correct
56 Correct 7 ms 9876 KB Output is correct
57 Correct 9 ms 9940 KB Output is correct
58 Correct 7 ms 9908 KB Output is correct
59 Correct 7 ms 9812 KB Output is correct
60 Correct 7 ms 9904 KB Output is correct
61 Correct 7 ms 9920 KB Output is correct
62 Correct 8 ms 9872 KB Output is correct
63 Correct 7 ms 9940 KB Output is correct
64 Correct 9 ms 9864 KB Output is correct
65 Correct 7 ms 9872 KB Output is correct
66 Correct 8 ms 9876 KB Output is correct
67 Correct 195 ms 30632 KB Output is correct
68 Correct 189 ms 29528 KB Output is correct
69 Correct 191 ms 29860 KB Output is correct
70 Correct 199 ms 30424 KB Output is correct
71 Correct 248 ms 30532 KB Output is correct
72 Correct 254 ms 29408 KB Output is correct
73 Correct 209 ms 30628 KB Output is correct
74 Correct 135 ms 27336 KB Output is correct
75 Correct 182 ms 25220 KB Output is correct
76 Correct 203 ms 28328 KB Output is correct
77 Correct 172 ms 29920 KB Output is correct
78 Correct 184 ms 29908 KB Output is correct
79 Correct 214 ms 30516 KB Output is correct
80 Correct 114 ms 29760 KB Output is correct
81 Correct 248 ms 28132 KB Output is correct
82 Correct 249 ms 28160 KB Output is correct
83 Correct 224 ms 30476 KB Output is correct
84 Correct 175 ms 29956 KB Output is correct
85 Correct 249 ms 28188 KB Output is correct
86 Correct 196 ms 30584 KB Output is correct
87 Correct 213 ms 30444 KB Output is correct
88 Correct 213 ms 26160 KB Output is correct
89 Correct 225 ms 27948 KB Output is correct
90 Correct 273 ms 27828 KB Output is correct
91 Correct 263 ms 27776 KB Output is correct
92 Correct 267 ms 27716 KB Output is correct
93 Correct 258 ms 27812 KB Output is correct
94 Correct 211 ms 27252 KB Output is correct
95 Correct 143 ms 27164 KB Output is correct
96 Correct 111 ms 28572 KB Output is correct
97 Correct 184 ms 21932 KB Output is correct
98 Correct 214 ms 27180 KB Output is correct
99 Correct 210 ms 27948 KB Output is correct
100 Correct 93 ms 15468 KB Output is correct
101 Correct 252 ms 27776 KB Output is correct
102 Correct 250 ms 25028 KB Output is correct
103 Correct 260 ms 25700 KB Output is correct
104 Correct 279 ms 26728 KB Output is correct