Submission #722893

# Submission time Handle Problem Language Result Execution time Memory
722893 2023-04-13T04:51:07 Z The_Samurai Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 15152 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int INF = 2e9;

int n, m, mx;
vector<vector<int>> g;
vector<bool> vis;
vector<int> a;

bool check(int i) {
    int sum = a[i];
    if (sum >= mx) return true;
    priority_queue<pair<int, int>> pq;
    bitset<200001> bs;
    bs[i] = 1;
    vector<int> way = {i};
    for (int u : g[i]) {
        bs[u] = 1;
        pq.push({-a[u], u});
    }
    while (!pq.empty()) {
        auto [need, u] = pq.top();
        pq.pop();
        need = -need;
        if (sum < need) break;
        way.emplace_back(u);
        sum += need;
        if (sum >= mx) return true;
        for (int v : g[u]) {
            if (!bs[v]) {
                bs[v] = 1;
                pq.push({-a[v], v});
            }
        }
    }
    for (int x: way) vis[x] = 1;
    return false;
}

void solve() {
    cin >> n >> m;
    a.assign(n + 1, 0);
    g.assign(n + 1, {});
    vis.assign(n + 1, 0);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    mx = *max_element(a.begin() + 1, a.end());
    for (int i = 1; i <= n; i++) {
        if (vis[i]) {
            cout << 0;
            continue;
        }
        cout << check(i);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> queries;
#else
    //    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
//        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 8 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 407 ms 12412 KB Output is correct
4 Correct 164 ms 13548 KB Output is correct
5 Correct 271 ms 11892 KB Output is correct
6 Correct 298 ms 12260 KB Output is correct
7 Correct 296 ms 12244 KB Output is correct
8 Correct 302 ms 12360 KB Output is correct
9 Correct 246 ms 12380 KB Output is correct
10 Correct 232 ms 13084 KB Output is correct
11 Correct 129 ms 13016 KB Output is correct
12 Correct 165 ms 12260 KB Output is correct
13 Correct 120 ms 13228 KB Output is correct
14 Correct 106 ms 13188 KB Output is correct
15 Correct 387 ms 12232 KB Output is correct
16 Execution timed out 1084 ms 12032 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 282 ms 12220 KB Output is correct
3 Correct 260 ms 12332 KB Output is correct
4 Correct 123 ms 12176 KB Output is correct
5 Correct 126 ms 13308 KB Output is correct
6 Correct 265 ms 12396 KB Output is correct
7 Correct 288 ms 12180 KB Output is correct
8 Correct 272 ms 12312 KB Output is correct
9 Execution timed out 1087 ms 12048 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 293 ms 12224 KB Output is correct
3 Correct 308 ms 12224 KB Output is correct
4 Correct 272 ms 12348 KB Output is correct
5 Correct 136 ms 12192 KB Output is correct
6 Correct 111 ms 11760 KB Output is correct
7 Correct 284 ms 15152 KB Output is correct
8 Execution timed out 1079 ms 14588 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 8 ms 468 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 407 ms 12412 KB Output is correct
18 Correct 164 ms 13548 KB Output is correct
19 Correct 271 ms 11892 KB Output is correct
20 Correct 298 ms 12260 KB Output is correct
21 Correct 296 ms 12244 KB Output is correct
22 Correct 302 ms 12360 KB Output is correct
23 Correct 246 ms 12380 KB Output is correct
24 Correct 232 ms 13084 KB Output is correct
25 Correct 129 ms 13016 KB Output is correct
26 Correct 165 ms 12260 KB Output is correct
27 Correct 120 ms 13228 KB Output is correct
28 Correct 106 ms 13188 KB Output is correct
29 Correct 387 ms 12232 KB Output is correct
30 Execution timed out 1084 ms 12032 KB Time limit exceeded
31 Halted 0 ms 0 KB -