Submission #722894

# Submission time Handle Problem Language Result Execution time Memory
722894 2023-04-13T04:55:23 Z The_Samurai Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 15292 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<int> a, ans;

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) {
            for (int v : g[i]) {
                if (a[i] <= a[v]) {
                    ans[v] = 1;
                }
            }
            return true;
        }
        for (int v : g[u]) {
            if (!bs[v]) {
                bs[v] = 1;
                pq.push({-a[v], v});
            }
        }
    }
    for (int x: way) ans[x] = 0;
    return false;
}

void solve() {
    cin >> n >> m;
    a.assign(n + 1, 0);
    g.assign(n + 1, {});
    ans.assign(n + 1, -1);
    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 (ans[i] != -1) {
            cout << ans[i];
            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 2 ms 444 KB Output is correct
5 Correct 3 ms 440 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 2 ms 468 KB Output is correct
10 Correct 3 ms 464 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 464 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 8 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 359 ms 13076 KB Output is correct
4 Correct 132 ms 14360 KB Output is correct
5 Correct 295 ms 12660 KB Output is correct
6 Correct 277 ms 13044 KB Output is correct
7 Correct 271 ms 13184 KB Output is correct
8 Correct 219 ms 13148 KB Output is correct
9 Correct 258 ms 12968 KB Output is correct
10 Correct 230 ms 13792 KB Output is correct
11 Correct 84 ms 13932 KB Output is correct
12 Correct 176 ms 13044 KB Output is correct
13 Correct 133 ms 13960 KB Output is correct
14 Correct 133 ms 13932 KB Output is correct
15 Correct 374 ms 13060 KB Output is correct
16 Execution timed out 1077 ms 12788 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 256 ms 13032 KB Output is correct
3 Correct 281 ms 12976 KB Output is correct
4 Correct 104 ms 13008 KB Output is correct
5 Correct 112 ms 14016 KB Output is correct
6 Correct 239 ms 13096 KB Output is correct
7 Correct 237 ms 12988 KB Output is correct
8 Correct 211 ms 12996 KB Output is correct
9 Execution timed out 1082 ms 12784 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 327 ms 12984 KB Output is correct
3 Correct 304 ms 13104 KB Output is correct
4 Correct 268 ms 13188 KB Output is correct
5 Correct 159 ms 13084 KB Output is correct
6 Correct 123 ms 12440 KB Output is correct
7 Correct 272 ms 13956 KB Output is correct
8 Execution timed out 1080 ms 15292 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 2 ms 444 KB Output is correct
5 Correct 3 ms 440 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 2 ms 468 KB Output is correct
10 Correct 3 ms 464 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 464 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 8 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 359 ms 13076 KB Output is correct
18 Correct 132 ms 14360 KB Output is correct
19 Correct 295 ms 12660 KB Output is correct
20 Correct 277 ms 13044 KB Output is correct
21 Correct 271 ms 13184 KB Output is correct
22 Correct 219 ms 13148 KB Output is correct
23 Correct 258 ms 12968 KB Output is correct
24 Correct 230 ms 13792 KB Output is correct
25 Correct 84 ms 13932 KB Output is correct
26 Correct 176 ms 13044 KB Output is correct
27 Correct 133 ms 13960 KB Output is correct
28 Correct 133 ms 13932 KB Output is correct
29 Correct 374 ms 13060 KB Output is correct
30 Execution timed out 1077 ms 12788 KB Time limit exceeded
31 Halted 0 ms 0 KB -