답안 #837605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837605 2023-08-25T12:44:12 Z d4xn Stranded Far From Home (BOI22_island) C++17
100 / 100
332 ms 69392 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 2e5+5;

int n, m, a[N], p[N], sz[N], dp[N];
vector<int> adj[N];
pair<int, int> s[N];
set<pair<int, int>> st[N];
bitset<N> ok;

int findSet(int x) {
  return p[x] = (p[x] == x ? x : findSet(p[x]));
}

void unite(int x, int y) {
  int X = x;

  x = findSet(x);
  y = findSet(y);
  if (x == y) return;

  if (sz[x] < sz[y]) {
    swap(x, y);
  }

  p[y] = x;
  sz[x] += sz[y];

  for (pair<int, int> z : st[y]) {
    st[x].insert(z);
  }

  while (*st[x].begin() <= make_pair(a[X], X)) st[x].erase(st[x].begin());
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  a[n] = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s[i] = make_pair(a[i], i);
  }
  sort(s, s+n);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  for (int i = 0; i < n; i++) {
    p[i] = i;
    sz[i] = a[i];

    st[i].insert(make_pair(INT_MAX, n));
    for (int& j : adj[i]) {
      if (make_pair(a[j], j) > make_pair(a[i], i)) st[i].insert(make_pair(a[j], j));
    }
  }

  for (int i = 0; i < n; i++) {
    int x = s[i].second;

    for (int& j : adj[x]) {
      if (make_pair(a[j], j) < make_pair(a[x], x)) unite(x, j);
    }

    int y = findSet(x);
    int z = sz[y];
    int nwMn = st[y].begin()->second;

    if (nwMn == n) {
      dp[x] = x;
      ok[x] = 1;
    }
    else if (a[nwMn] <= z) {
      dp[x] = nwMn;
    }
    else {
      dp[x] = x;
    }
  }

  for (int i = n-1; i >= 0; i--) {
    int x = s[i].second;
    ok[x] = ok[dp[x]];
  }

  for (int i = 0; i < n; i++) {
    cout << ok[i];
  }
  cout << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14420 KB Output is correct
2 Correct 6 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14856 KB Output is correct
5 Correct 8 ms 14804 KB Output is correct
6 Correct 8 ms 14804 KB Output is correct
7 Correct 7 ms 14804 KB Output is correct
8 Correct 9 ms 14804 KB Output is correct
9 Correct 7 ms 14932 KB Output is correct
10 Correct 10 ms 14848 KB Output is correct
11 Correct 8 ms 14900 KB Output is correct
12 Correct 7 ms 14804 KB Output is correct
13 Correct 7 ms 14804 KB Output is correct
14 Correct 8 ms 14804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 172 ms 56396 KB Output is correct
4 Correct 148 ms 56268 KB Output is correct
5 Correct 212 ms 54940 KB Output is correct
6 Correct 235 ms 56268 KB Output is correct
7 Correct 214 ms 56268 KB Output is correct
8 Correct 232 ms 60072 KB Output is correct
9 Correct 152 ms 57588 KB Output is correct
10 Correct 182 ms 56812 KB Output is correct
11 Correct 240 ms 56812 KB Output is correct
12 Correct 217 ms 59060 KB Output is correct
13 Correct 147 ms 55208 KB Output is correct
14 Correct 158 ms 55520 KB Output is correct
15 Correct 142 ms 55244 KB Output is correct
16 Correct 104 ms 54784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 235 ms 59772 KB Output is correct
3 Correct 241 ms 60100 KB Output is correct
4 Correct 160 ms 55296 KB Output is correct
5 Correct 170 ms 55296 KB Output is correct
6 Correct 239 ms 60076 KB Output is correct
7 Correct 177 ms 55376 KB Output is correct
8 Correct 160 ms 55244 KB Output is correct
9 Correct 103 ms 54840 KB Output is correct
10 Correct 168 ms 58468 KB Output is correct
11 Correct 206 ms 59436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 300 ms 62100 KB Output is correct
3 Correct 303 ms 60972 KB Output is correct
4 Correct 278 ms 60176 KB Output is correct
5 Correct 264 ms 59496 KB Output is correct
6 Correct 237 ms 60576 KB Output is correct
7 Correct 206 ms 56828 KB Output is correct
8 Correct 164 ms 69300 KB Output is correct
9 Correct 238 ms 49424 KB Output is correct
10 Correct 263 ms 59648 KB Output is correct
11 Correct 205 ms 59228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14420 KB Output is correct
2 Correct 6 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14856 KB Output is correct
5 Correct 8 ms 14804 KB Output is correct
6 Correct 8 ms 14804 KB Output is correct
7 Correct 7 ms 14804 KB Output is correct
8 Correct 9 ms 14804 KB Output is correct
9 Correct 7 ms 14932 KB Output is correct
10 Correct 10 ms 14848 KB Output is correct
11 Correct 8 ms 14900 KB Output is correct
12 Correct 7 ms 14804 KB Output is correct
13 Correct 7 ms 14804 KB Output is correct
14 Correct 8 ms 14804 KB Output is correct
15 Correct 6 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 172 ms 56396 KB Output is correct
18 Correct 148 ms 56268 KB Output is correct
19 Correct 212 ms 54940 KB Output is correct
20 Correct 235 ms 56268 KB Output is correct
21 Correct 214 ms 56268 KB Output is correct
22 Correct 232 ms 60072 KB Output is correct
23 Correct 152 ms 57588 KB Output is correct
24 Correct 182 ms 56812 KB Output is correct
25 Correct 240 ms 56812 KB Output is correct
26 Correct 217 ms 59060 KB Output is correct
27 Correct 147 ms 55208 KB Output is correct
28 Correct 158 ms 55520 KB Output is correct
29 Correct 142 ms 55244 KB Output is correct
30 Correct 104 ms 54784 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 235 ms 59772 KB Output is correct
33 Correct 241 ms 60100 KB Output is correct
34 Correct 160 ms 55296 KB Output is correct
35 Correct 170 ms 55296 KB Output is correct
36 Correct 239 ms 60076 KB Output is correct
37 Correct 177 ms 55376 KB Output is correct
38 Correct 160 ms 55244 KB Output is correct
39 Correct 103 ms 54840 KB Output is correct
40 Correct 168 ms 58468 KB Output is correct
41 Correct 206 ms 59436 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 300 ms 62100 KB Output is correct
44 Correct 303 ms 60972 KB Output is correct
45 Correct 278 ms 60176 KB Output is correct
46 Correct 264 ms 59496 KB Output is correct
47 Correct 237 ms 60576 KB Output is correct
48 Correct 206 ms 56828 KB Output is correct
49 Correct 164 ms 69300 KB Output is correct
50 Correct 238 ms 49424 KB Output is correct
51 Correct 263 ms 59648 KB Output is correct
52 Correct 205 ms 59228 KB Output is correct
53 Correct 7 ms 14420 KB Output is correct
54 Correct 7 ms 14420 KB Output is correct
55 Correct 7 ms 14420 KB Output is correct
56 Correct 8 ms 14804 KB Output is correct
57 Correct 9 ms 14804 KB Output is correct
58 Correct 8 ms 14804 KB Output is correct
59 Correct 8 ms 14804 KB Output is correct
60 Correct 7 ms 14804 KB Output is correct
61 Correct 8 ms 14932 KB Output is correct
62 Correct 8 ms 14804 KB Output is correct
63 Correct 8 ms 14804 KB Output is correct
64 Correct 8 ms 14804 KB Output is correct
65 Correct 8 ms 14804 KB Output is correct
66 Correct 8 ms 14804 KB Output is correct
67 Correct 156 ms 56268 KB Output is correct
68 Correct 147 ms 56224 KB Output is correct
69 Correct 197 ms 54984 KB Output is correct
70 Correct 198 ms 56188 KB Output is correct
71 Correct 205 ms 56356 KB Output is correct
72 Correct 289 ms 60080 KB Output is correct
73 Correct 166 ms 57604 KB Output is correct
74 Correct 192 ms 56812 KB Output is correct
75 Correct 225 ms 56888 KB Output is correct
76 Correct 219 ms 59064 KB Output is correct
77 Correct 150 ms 55208 KB Output is correct
78 Correct 147 ms 55208 KB Output is correct
79 Correct 147 ms 55244 KB Output is correct
80 Correct 103 ms 54840 KB Output is correct
81 Correct 265 ms 60012 KB Output is correct
82 Correct 257 ms 60000 KB Output is correct
83 Correct 169 ms 55372 KB Output is correct
84 Correct 146 ms 55204 KB Output is correct
85 Correct 251 ms 60140 KB Output is correct
86 Correct 168 ms 55264 KB Output is correct
87 Correct 170 ms 55232 KB Output is correct
88 Correct 166 ms 58444 KB Output is correct
89 Correct 183 ms 59360 KB Output is correct
90 Correct 332 ms 62328 KB Output is correct
91 Correct 290 ms 60876 KB Output is correct
92 Correct 285 ms 60088 KB Output is correct
93 Correct 249 ms 59576 KB Output is correct
94 Correct 275 ms 60492 KB Output is correct
95 Correct 198 ms 56788 KB Output is correct
96 Correct 163 ms 69392 KB Output is correct
97 Correct 193 ms 49484 KB Output is correct
98 Correct 256 ms 59756 KB Output is correct
99 Correct 189 ms 59176 KB Output is correct
100 Correct 100 ms 32076 KB Output is correct
101 Correct 320 ms 61132 KB Output is correct
102 Correct 259 ms 59892 KB Output is correct
103 Correct 294 ms 61852 KB Output is correct
104 Correct 323 ms 62712 KB Output is correct