Submission #715001

# Submission time Handle Problem Language Result Execution time Memory
715001 2023-03-25T17:24:45 Z aykhn Stranded Far From Home (BOI22_island) C++14
100 / 100
466 ms 43228 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;
                }
                d[z].clear();
            }

            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++)
      |                                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14432 KB Output is correct
4 Correct 9 ms 14572 KB Output is correct
5 Correct 10 ms 14552 KB Output is correct
6 Correct 10 ms 14580 KB Output is correct
7 Correct 13 ms 14572 KB Output is correct
8 Correct 12 ms 14576 KB Output is correct
9 Correct 10 ms 14560 KB Output is correct
10 Correct 10 ms 14628 KB Output is correct
11 Correct 10 ms 14584 KB Output is correct
12 Correct 10 ms 14580 KB Output is correct
13 Correct 10 ms 14548 KB Output is correct
14 Correct 10 ms 14576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14428 KB Output is correct
3 Correct 348 ms 33180 KB Output is correct
4 Correct 272 ms 32636 KB Output is correct
5 Correct 347 ms 35684 KB Output is correct
6 Correct 396 ms 36468 KB Output is correct
7 Correct 369 ms 36288 KB Output is correct
8 Correct 375 ms 32712 KB Output is correct
9 Correct 368 ms 40136 KB Output is correct
10 Correct 287 ms 31320 KB Output is correct
11 Correct 322 ms 34260 KB Output is correct
12 Correct 319 ms 32900 KB Output is correct
13 Correct 263 ms 31888 KB Output is correct
14 Correct 302 ms 31872 KB Output is correct
15 Correct 304 ms 31732 KB Output is correct
16 Correct 241 ms 31636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14324 KB Output is correct
2 Correct 407 ms 37156 KB Output is correct
3 Correct 374 ms 40532 KB Output is correct
4 Correct 336 ms 35088 KB Output is correct
5 Correct 267 ms 33632 KB Output is correct
6 Correct 392 ms 40508 KB Output is correct
7 Correct 307 ms 35160 KB Output is correct
8 Correct 318 ms 35200 KB Output is correct
9 Correct 232 ms 34196 KB Output is correct
10 Correct 292 ms 33408 KB Output is correct
11 Correct 286 ms 34296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 426 ms 33860 KB Output is correct
3 Correct 397 ms 36924 KB Output is correct
4 Correct 393 ms 38852 KB Output is correct
5 Correct 417 ms 40976 KB Output is correct
6 Correct 356 ms 37480 KB Output is correct
7 Correct 307 ms 36560 KB Output is correct
8 Correct 215 ms 34532 KB Output is correct
9 Correct 254 ms 27852 KB Output is correct
10 Correct 333 ms 41964 KB Output is correct
11 Correct 295 ms 34132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14432 KB Output is correct
4 Correct 9 ms 14572 KB Output is correct
5 Correct 10 ms 14552 KB Output is correct
6 Correct 10 ms 14580 KB Output is correct
7 Correct 13 ms 14572 KB Output is correct
8 Correct 12 ms 14576 KB Output is correct
9 Correct 10 ms 14560 KB Output is correct
10 Correct 10 ms 14628 KB Output is correct
11 Correct 10 ms 14584 KB Output is correct
12 Correct 10 ms 14580 KB Output is correct
13 Correct 10 ms 14548 KB Output is correct
14 Correct 10 ms 14576 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14428 KB Output is correct
17 Correct 348 ms 33180 KB Output is correct
18 Correct 272 ms 32636 KB Output is correct
19 Correct 347 ms 35684 KB Output is correct
20 Correct 396 ms 36468 KB Output is correct
21 Correct 369 ms 36288 KB Output is correct
22 Correct 375 ms 32712 KB Output is correct
23 Correct 368 ms 40136 KB Output is correct
24 Correct 287 ms 31320 KB Output is correct
25 Correct 322 ms 34260 KB Output is correct
26 Correct 319 ms 32900 KB Output is correct
27 Correct 263 ms 31888 KB Output is correct
28 Correct 302 ms 31872 KB Output is correct
29 Correct 304 ms 31732 KB Output is correct
30 Correct 241 ms 31636 KB Output is correct
31 Correct 8 ms 14324 KB Output is correct
32 Correct 407 ms 37156 KB Output is correct
33 Correct 374 ms 40532 KB Output is correct
34 Correct 336 ms 35088 KB Output is correct
35 Correct 267 ms 33632 KB Output is correct
36 Correct 392 ms 40508 KB Output is correct
37 Correct 307 ms 35160 KB Output is correct
38 Correct 318 ms 35200 KB Output is correct
39 Correct 232 ms 34196 KB Output is correct
40 Correct 292 ms 33408 KB Output is correct
41 Correct 286 ms 34296 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 426 ms 33860 KB Output is correct
44 Correct 397 ms 36924 KB Output is correct
45 Correct 393 ms 38852 KB Output is correct
46 Correct 417 ms 40976 KB Output is correct
47 Correct 356 ms 37480 KB Output is correct
48 Correct 307 ms 36560 KB Output is correct
49 Correct 215 ms 34532 KB Output is correct
50 Correct 254 ms 27852 KB Output is correct
51 Correct 333 ms 41964 KB Output is correct
52 Correct 295 ms 34132 KB Output is correct
53 Correct 8 ms 14372 KB Output is correct
54 Correct 9 ms 14420 KB Output is correct
55 Correct 8 ms 14548 KB Output is correct
56 Correct 12 ms 14572 KB Output is correct
57 Correct 11 ms 14556 KB Output is correct
58 Correct 10 ms 14548 KB Output is correct
59 Correct 9 ms 14568 KB Output is correct
60 Correct 11 ms 14572 KB Output is correct
61 Correct 10 ms 14548 KB Output is correct
62 Correct 11 ms 14548 KB Output is correct
63 Correct 10 ms 14580 KB Output is correct
64 Correct 11 ms 14612 KB Output is correct
65 Correct 9 ms 14548 KB Output is correct
66 Correct 12 ms 14576 KB Output is correct
67 Correct 290 ms 36444 KB Output is correct
68 Correct 280 ms 34596 KB Output is correct
69 Correct 331 ms 38752 KB Output is correct
70 Correct 380 ms 39636 KB Output is correct
71 Correct 335 ms 39644 KB Output is correct
72 Correct 323 ms 36048 KB Output is correct
73 Correct 329 ms 43228 KB Output is correct
74 Correct 313 ms 33780 KB Output is correct
75 Correct 275 ms 36460 KB Output is correct
76 Correct 288 ms 34880 KB Output is correct
77 Correct 256 ms 33496 KB Output is correct
78 Correct 271 ms 33924 KB Output is correct
79 Correct 308 ms 35028 KB Output is correct
80 Correct 214 ms 34176 KB Output is correct
81 Correct 412 ms 40476 KB Output is correct
82 Correct 377 ms 40512 KB Output is correct
83 Correct 364 ms 35152 KB Output is correct
84 Correct 264 ms 33692 KB Output is correct
85 Correct 409 ms 40524 KB Output is correct
86 Correct 323 ms 35156 KB Output is correct
87 Correct 292 ms 35248 KB Output is correct
88 Correct 296 ms 33332 KB Output is correct
89 Correct 292 ms 34340 KB Output is correct
90 Correct 404 ms 37188 KB Output is correct
91 Correct 399 ms 37960 KB Output is correct
92 Correct 466 ms 39956 KB Output is correct
93 Correct 388 ms 41928 KB Output is correct
94 Correct 358 ms 38452 KB Output is correct
95 Correct 279 ms 37460 KB Output is correct
96 Correct 208 ms 34512 KB Output is correct
97 Correct 211 ms 27816 KB Output is correct
98 Correct 378 ms 42020 KB Output is correct
99 Correct 293 ms 34140 KB Output is correct
100 Correct 124 ms 20864 KB Output is correct
101 Correct 385 ms 38300 KB Output is correct
102 Correct 304 ms 34808 KB Output is correct
103 Correct 392 ms 33432 KB Output is correct
104 Correct 379 ms 36292 KB Output is correct