답안 #963382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963382 2024-04-14T22:51:01 Z Spade1 Stranded Far From Home (BOI22_island) C++14
100 / 100
96 ms 17420 KB
#pragma once
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pld> vpld;
typedef vector<vi> vvi;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define ins insert
#define int ll

template<typename T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;
const int INF = 0x3fffffff;
const ll LINF = 0x1fffffffffffffff;
const char nl = '\n';
const int MX = 2e5 + 3;

ll s[MX], ans[MX], sz[MX], rep[MX];
vector<t3> edges;

int f(int i) {
  if (i == rep[i]) return i;
  int par = f(rep[i]);
  if (ans[rep[i]] == 0) ans[i] = 0;
  return rep[i] = par;
}

void solve() {
  int n, m; cin >> n >> m;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i]; 
    sz[i] = s[i];
    ans[i] = 1;
    rep[i] = i;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v; cin >> u >> v;
    edges.pb({max(s[u], s[v]), u, v});
  }
  sort(all(edges));
  for (auto [M, u, v] : edges) {
    int fu = f(u), fv = f(v);
    if (fu == fv) continue;
    if (s[fu] < s[fv]) swap(fu, fv);
    if (s[fu] > sz[fv]) ans[fv] = 0;
    sz[fu] += sz[fv];
    rep[fv] = rep[fu];
  }
  for (int i = 1; i <= n; ++i) f(i), cout << ans[i];
  cout << nl;
}

signed main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0); cin.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--) { solve(); }
  return 0;
}

Compilation message

island.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
island.cpp: In function 'void solve()':
island.cpp:70:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   70 |   for (auto [M, u, v] : edges) {
      |             ^
island.cpp:58:7: warning: unused variable 'mx' [-Wunused-variable]
   58 |   int mx = 0;
      |       ^~
island.cpp: At global scope:
island.cpp:82:8: warning: first argument of 'int main(ll, char**)' should be 'int' [-Wmain]
   82 | signed main(int argc, char* argv[]) {
      |        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 580 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 684 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 83 ms 14976 KB Output is correct
4 Correct 68 ms 14436 KB Output is correct
5 Correct 78 ms 15100 KB Output is correct
6 Correct 74 ms 14876 KB Output is correct
7 Correct 77 ms 15036 KB Output is correct
8 Correct 84 ms 15128 KB Output is correct
9 Correct 73 ms 14776 KB Output is correct
10 Correct 72 ms 14748 KB Output is correct
11 Correct 78 ms 15024 KB Output is correct
12 Correct 75 ms 14216 KB Output is correct
13 Correct 64 ms 14780 KB Output is correct
14 Correct 66 ms 14608 KB Output is correct
15 Correct 76 ms 15292 KB Output is correct
16 Correct 56 ms 14516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 79 ms 15232 KB Output is correct
3 Correct 77 ms 16756 KB Output is correct
4 Correct 77 ms 17416 KB Output is correct
5 Correct 80 ms 15520 KB Output is correct
6 Correct 81 ms 16836 KB Output is correct
7 Correct 69 ms 17088 KB Output is correct
8 Correct 77 ms 16772 KB Output is correct
9 Correct 51 ms 15908 KB Output is correct
10 Correct 69 ms 16064 KB Output is correct
11 Correct 76 ms 15108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 88 ms 15092 KB Output is correct
3 Correct 88 ms 16668 KB Output is correct
4 Correct 90 ms 16588 KB Output is correct
5 Correct 82 ms 16580 KB Output is correct
6 Correct 94 ms 16324 KB Output is correct
7 Correct 71 ms 16592 KB Output is correct
8 Correct 61 ms 15552 KB Output is correct
9 Correct 66 ms 11712 KB Output is correct
10 Correct 72 ms 15196 KB Output is correct
11 Correct 71 ms 15044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 580 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 684 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 83 ms 14976 KB Output is correct
18 Correct 68 ms 14436 KB Output is correct
19 Correct 78 ms 15100 KB Output is correct
20 Correct 74 ms 14876 KB Output is correct
21 Correct 77 ms 15036 KB Output is correct
22 Correct 84 ms 15128 KB Output is correct
23 Correct 73 ms 14776 KB Output is correct
24 Correct 72 ms 14748 KB Output is correct
25 Correct 78 ms 15024 KB Output is correct
26 Correct 75 ms 14216 KB Output is correct
27 Correct 64 ms 14780 KB Output is correct
28 Correct 66 ms 14608 KB Output is correct
29 Correct 76 ms 15292 KB Output is correct
30 Correct 56 ms 14516 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 79 ms 15232 KB Output is correct
33 Correct 77 ms 16756 KB Output is correct
34 Correct 77 ms 17416 KB Output is correct
35 Correct 80 ms 15520 KB Output is correct
36 Correct 81 ms 16836 KB Output is correct
37 Correct 69 ms 17088 KB Output is correct
38 Correct 77 ms 16772 KB Output is correct
39 Correct 51 ms 15908 KB Output is correct
40 Correct 69 ms 16064 KB Output is correct
41 Correct 76 ms 15108 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 88 ms 15092 KB Output is correct
44 Correct 88 ms 16668 KB Output is correct
45 Correct 90 ms 16588 KB Output is correct
46 Correct 82 ms 16580 KB Output is correct
47 Correct 94 ms 16324 KB Output is correct
48 Correct 71 ms 16592 KB Output is correct
49 Correct 61 ms 15552 KB Output is correct
50 Correct 66 ms 11712 KB Output is correct
51 Correct 72 ms 15196 KB Output is correct
52 Correct 71 ms 15044 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 2 ms 612 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 2652 KB Output is correct
67 Correct 75 ms 16692 KB Output is correct
68 Correct 68 ms 15352 KB Output is correct
69 Correct 76 ms 16416 KB Output is correct
70 Correct 75 ms 16476 KB Output is correct
71 Correct 76 ms 16580 KB Output is correct
72 Correct 85 ms 16680 KB Output is correct
73 Correct 77 ms 16572 KB Output is correct
74 Correct 66 ms 16000 KB Output is correct
75 Correct 67 ms 16236 KB Output is correct
76 Correct 73 ms 15412 KB Output is correct
77 Correct 64 ms 15748 KB Output is correct
78 Correct 70 ms 16096 KB Output is correct
79 Correct 73 ms 16816 KB Output is correct
80 Correct 53 ms 15944 KB Output is correct
81 Correct 76 ms 16572 KB Output is correct
82 Correct 79 ms 17088 KB Output is correct
83 Correct 79 ms 17420 KB Output is correct
84 Correct 63 ms 15496 KB Output is correct
85 Correct 77 ms 16836 KB Output is correct
86 Correct 70 ms 16612 KB Output is correct
87 Correct 71 ms 16840 KB Output is correct
88 Correct 69 ms 16060 KB Output is correct
89 Correct 69 ms 15300 KB Output is correct
90 Correct 83 ms 16580 KB Output is correct
91 Correct 91 ms 16596 KB Output is correct
92 Correct 96 ms 16760 KB Output is correct
93 Correct 78 ms 16664 KB Output is correct
94 Correct 82 ms 16416 KB Output is correct
95 Correct 71 ms 16744 KB Output is correct
96 Correct 62 ms 15596 KB Output is correct
97 Correct 64 ms 12860 KB Output is correct
98 Correct 76 ms 15504 KB Output is correct
99 Correct 68 ms 15296 KB Output is correct
100 Correct 49 ms 10184 KB Output is correct
101 Correct 84 ms 16836 KB Output is correct
102 Correct 75 ms 15044 KB Output is correct
103 Correct 89 ms 15644 KB Output is correct
104 Correct 84 ms 16580 KB Output is correct