답안 #918830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918830 2024-01-30T13:44:42 Z vjudge1 Stranded Far From Home (BOI22_island) C++17
100 / 100
379 ms 53796 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;
 
ll n;
vector<ll> v(200001);
vector<ll> d[200001];
vector<ll> sum(200001);
vector<bool> ans(200001, true);
vector<ll> e(200001, -1);
vector<vector<ll>> adj(200001);
void init(int n)
{
    for (int i = 1; i <= n; i++)
    {
        d[i].pb(i);
        sum[i] = v[i];
    }
}
 
int get(int x)
{
    if (e[x] < 0) return x;
    return e[x] = get(e[x]);
}
 
int s(int x)
{
    return -e[get(x)];
}
 
void unite(int x, int y)
{
    x = get(x);
    y = get(y);
 
    if (x == y) return;
 
    if (e[x] > e[y]) swap(x, y);
 
    e[x] += e[y];
    e[y] = x;
 
    sum[x] += sum[y];
 
    for (int i = 0; i < d[y].size(); i++)
    {
        d[x].pb(d[y][i]);
    }
}
 
ll get_sum(int x)
{
    x = get(x);
    return sum[x];
}
 
int main()
{
    int m;
    cin >> n >> m;
    vector<pii> arr(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i];
        arr[i].fi = v[i];
        arr[i].se = i;
    }
 
    while (m--)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
 
    sort(arr.begin() + 1, arr.end());
 
    init(n);
 
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < adj[arr[i].se].size(); j++)
        {
            int x = arr[i].se;
            int y = adj[x][j];
            if (arr[i].fi < v[y]) continue;
 
            int z = get(y);
 
            if (sum[z] < arr[i].fi)
            {
                for (int k = 0; k < d[z].size(); k++)
                {
                    ans[d[z][k]] = false;
                }
            }
 
            unite(x, y);
        }
    }
 
    for (int i = 1; i <= n; i++) cout << ans[i];
}

Compilation message

island.cpp: In function 'void unite(int, int)':
island.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i < d[y].size(); i++)
      |                     ~~^~~~~~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         for (int j = 0; j < adj[arr[i].se].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~
island.cpp:115:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |                 for (int k = 0; k < d[z].size(); k++)
      |                                 ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 5 ms 14424 KB Output is correct
4 Correct 7 ms 14680 KB Output is correct
5 Correct 7 ms 14680 KB Output is correct
6 Correct 6 ms 14680 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 6 ms 14680 KB Output is correct
9 Correct 7 ms 14680 KB Output is correct
10 Correct 7 ms 14684 KB Output is correct
11 Correct 6 ms 14680 KB Output is correct
12 Correct 7 ms 14680 KB Output is correct
13 Correct 7 ms 14680 KB Output is correct
14 Correct 7 ms 14788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14424 KB Output is correct
2 Correct 5 ms 14424 KB Output is correct
3 Correct 224 ms 36940 KB Output is correct
4 Correct 191 ms 34500 KB Output is correct
5 Correct 243 ms 43636 KB Output is correct
6 Correct 271 ms 44556 KB Output is correct
7 Correct 260 ms 44856 KB Output is correct
8 Correct 248 ms 36124 KB Output is correct
9 Correct 244 ms 53640 KB Output is correct
10 Correct 201 ms 36812 KB Output is correct
11 Correct 199 ms 36544 KB Output is correct
12 Correct 251 ms 36496 KB Output is correct
13 Correct 182 ms 33488 KB Output is correct
14 Correct 212 ms 33748 KB Output is correct
15 Correct 203 ms 35028 KB Output is correct
16 Correct 169 ms 34244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14424 KB Output is correct
2 Correct 300 ms 47852 KB Output is correct
3 Correct 292 ms 47672 KB Output is correct
4 Correct 237 ms 35180 KB Output is correct
5 Correct 177 ms 34248 KB Output is correct
6 Correct 311 ms 47720 KB Output is correct
7 Correct 296 ms 35416 KB Output is correct
8 Correct 279 ms 35160 KB Output is correct
9 Correct 170 ms 34244 KB Output is correct
10 Correct 197 ms 34508 KB Output is correct
11 Correct 261 ms 36564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 368 ms 40396 KB Output is correct
3 Correct 333 ms 41508 KB Output is correct
4 Correct 370 ms 43160 KB Output is correct
5 Correct 343 ms 42004 KB Output is correct
6 Correct 325 ms 38504 KB Output is correct
7 Correct 229 ms 37656 KB Output is correct
8 Correct 170 ms 35532 KB Output is correct
9 Correct 165 ms 29132 KB Output is correct
10 Correct 319 ms 42032 KB Output is correct
11 Correct 286 ms 36440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 5 ms 14424 KB Output is correct
4 Correct 7 ms 14680 KB Output is correct
5 Correct 7 ms 14680 KB Output is correct
6 Correct 6 ms 14680 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 6 ms 14680 KB Output is correct
9 Correct 7 ms 14680 KB Output is correct
10 Correct 7 ms 14684 KB Output is correct
11 Correct 6 ms 14680 KB Output is correct
12 Correct 7 ms 14680 KB Output is correct
13 Correct 7 ms 14680 KB Output is correct
14 Correct 7 ms 14788 KB Output is correct
15 Correct 5 ms 14424 KB Output is correct
16 Correct 5 ms 14424 KB Output is correct
17 Correct 224 ms 36940 KB Output is correct
18 Correct 191 ms 34500 KB Output is correct
19 Correct 243 ms 43636 KB Output is correct
20 Correct 271 ms 44556 KB Output is correct
21 Correct 260 ms 44856 KB Output is correct
22 Correct 248 ms 36124 KB Output is correct
23 Correct 244 ms 53640 KB Output is correct
24 Correct 201 ms 36812 KB Output is correct
25 Correct 199 ms 36544 KB Output is correct
26 Correct 251 ms 36496 KB Output is correct
27 Correct 182 ms 33488 KB Output is correct
28 Correct 212 ms 33748 KB Output is correct
29 Correct 203 ms 35028 KB Output is correct
30 Correct 169 ms 34244 KB Output is correct
31 Correct 5 ms 14424 KB Output is correct
32 Correct 300 ms 47852 KB Output is correct
33 Correct 292 ms 47672 KB Output is correct
34 Correct 237 ms 35180 KB Output is correct
35 Correct 177 ms 34248 KB Output is correct
36 Correct 311 ms 47720 KB Output is correct
37 Correct 296 ms 35416 KB Output is correct
38 Correct 279 ms 35160 KB Output is correct
39 Correct 170 ms 34244 KB Output is correct
40 Correct 197 ms 34508 KB Output is correct
41 Correct 261 ms 36564 KB Output is correct
42 Correct 5 ms 14428 KB Output is correct
43 Correct 368 ms 40396 KB Output is correct
44 Correct 333 ms 41508 KB Output is correct
45 Correct 370 ms 43160 KB Output is correct
46 Correct 343 ms 42004 KB Output is correct
47 Correct 325 ms 38504 KB Output is correct
48 Correct 229 ms 37656 KB Output is correct
49 Correct 170 ms 35532 KB Output is correct
50 Correct 165 ms 29132 KB Output is correct
51 Correct 319 ms 42032 KB Output is correct
52 Correct 286 ms 36440 KB Output is correct
53 Correct 6 ms 14564 KB Output is correct
54 Correct 7 ms 14428 KB Output is correct
55 Correct 6 ms 14428 KB Output is correct
56 Correct 8 ms 14868 KB Output is correct
57 Correct 8 ms 14684 KB Output is correct
58 Correct 8 ms 14616 KB Output is correct
59 Correct 7 ms 14684 KB Output is correct
60 Correct 8 ms 14684 KB Output is correct
61 Correct 8 ms 14680 KB Output is correct
62 Correct 8 ms 14684 KB Output is correct
63 Correct 11 ms 14684 KB Output is correct
64 Correct 9 ms 14684 KB Output is correct
65 Correct 8 ms 14684 KB Output is correct
66 Correct 7 ms 14936 KB Output is correct
67 Correct 240 ms 36968 KB Output is correct
68 Correct 229 ms 34748 KB Output is correct
69 Correct 300 ms 43600 KB Output is correct
70 Correct 309 ms 44660 KB Output is correct
71 Correct 323 ms 45000 KB Output is correct
72 Correct 265 ms 36036 KB Output is correct
73 Correct 250 ms 53796 KB Output is correct
74 Correct 244 ms 37328 KB Output is correct
75 Correct 201 ms 36544 KB Output is correct
76 Correct 305 ms 36616 KB Output is correct
77 Correct 245 ms 33732 KB Output is correct
78 Correct 241 ms 33780 KB Output is correct
79 Correct 228 ms 35332 KB Output is correct
80 Correct 179 ms 34348 KB Output is correct
81 Correct 322 ms 47528 KB Output is correct
82 Correct 379 ms 47664 KB Output is correct
83 Correct 260 ms 35424 KB Output is correct
84 Correct 176 ms 34268 KB Output is correct
85 Correct 325 ms 47588 KB Output is correct
86 Correct 225 ms 35280 KB Output is correct
87 Correct 249 ms 35276 KB Output is correct
88 Correct 198 ms 34508 KB Output is correct
89 Correct 247 ms 36568 KB Output is correct
90 Correct 317 ms 40256 KB Output is correct
91 Correct 319 ms 41668 KB Output is correct
92 Correct 345 ms 43244 KB Output is correct
93 Correct 336 ms 41924 KB Output is correct
94 Correct 275 ms 38596 KB Output is correct
95 Correct 219 ms 37572 KB Output is correct
96 Correct 168 ms 35528 KB Output is correct
97 Correct 160 ms 29032 KB Output is correct
98 Correct 275 ms 42356 KB Output is correct
99 Correct 260 ms 36304 KB Output is correct
100 Correct 85 ms 20924 KB Output is correct
101 Correct 312 ms 42944 KB Output is correct
102 Correct 267 ms 35084 KB Output is correct
103 Correct 276 ms 35524 KB Output is correct
104 Correct 307 ms 39316 KB Output is correct